0.8.38 change profile validation

This commit is contained in:
SDE
2023-12-15 15:11:35 +03:00
parent a3faa17754
commit 9c971a6fa4
6 changed files with 46 additions and 3 deletions

View File

@@ -29,6 +29,13 @@ class RegistrationForm(forms.Form):
tel = forms.CharField()
agreement = forms.BooleanField(initial=False, required=True)
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args)
if 'not_required_password' in kwargs.keys() and kwargs['not_required_password']:
self.fields['password'].required = False
self.fields['confirm_password'].required = False
def clean(self):
cleaned_data = super().clean()
i = 0
@@ -39,6 +46,12 @@ class RegistrationForm(forms.Form):
self.add_error(names[i], _('Обязательное поле'))
i += 1
if 'tel' in cleaned_data and 'tel' in cleaned_data:
from BaseModels.validators.form_field_validators import get_phone_valid_error
error = get_phone_valid_error(cleaned_data["tel"])
if error:
self.add_error('tel', error)
if cleaned_data and 'confirm_password' in cleaned_data and 'password' in cleaned_data:
if cleaned_data['confirm_password'] != cleaned_data['password']:
self.add_error("password", _('Пароль и подтверждение пароля не совпадают'))

View File

@@ -236,7 +236,14 @@ def change_profile_confirm_ajax(request):
data = json.loads(request.body)
from .forms import RegistrationForm
form = RegistrationForm(data)
kwargs = {'not_required_password': True}
form = RegistrationForm(data, **kwargs)
if not form.is_valid():
form.initial = form.cleaned_data
Dict = {'profile_form': form}
html = render_to_string('blocks/profile/b_profile.html', Dict, request=request)
return JsonResponse({'html': html}, status=400)
data_for_save = {}
users = User.objects.filter(id=request.user.id)