0.8.41 change profile validation

This commit is contained in:
SDE
2023-12-15 15:56:51 +03:00
parent 36fd9599af
commit f8d29d80b7
2 changed files with 9 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ class RegistrationForm(forms.Form):
required_password = True required_password = True
required_agreement = True required_agreement = True
required_email = True required_email = True
create_new_account = True
if 'not_required_password' in kwargs.keys() and kwargs['not_required_password']: if 'not_required_password' in kwargs.keys() and kwargs['not_required_password']:
required_password = False required_password = False
del kwargs['not_required_password'] del kwargs['not_required_password']
@@ -42,6 +43,9 @@ class RegistrationForm(forms.Form):
if 'not_required_email' in kwargs.keys() and kwargs['not_required_email']: if 'not_required_email' in kwargs.keys() and kwargs['not_required_email']:
required_email = False required_email = False
del kwargs['not_required_email'] del kwargs['not_required_email']
if 'create_new_account' in kwargs.keys() and not kwargs['create_new_account']:
create_new_account = False
del kwargs['create_new_account']
super(RegistrationForm, self).__init__(*args, **kwargs) super(RegistrationForm, self).__init__(*args, **kwargs)
@@ -52,6 +56,8 @@ class RegistrationForm(forms.Form):
self.fields['email'].required = required_email self.fields['email'].required = required_email
self.create_new_account = create_new_account
def clean(self): def clean(self):
cleaned_data = super().clean() cleaned_data = super().clean()
# i = 0 # i = 0
@@ -73,7 +79,7 @@ class RegistrationForm(forms.Form):
self.add_error("password", _('Пароль и подтверждение пароля не совпадают')) self.add_error("password", _('Пароль и подтверждение пароля не совпадают'))
self.add_error("confirm_password", _('Пароль и подтверждение пароля не совпадают')) self.add_error("confirm_password", _('Пароль и подтверждение пароля не совпадают'))
if cleaned_data and 'email' in cleaned_data: if self.create_new_account and cleaned_data and 'email' in cleaned_data:
users = User.objects.filter(email=cleaned_data['email']) users = User.objects.filter(email=cleaned_data['email'])
if users: if users:
self.add_error('email', _("Пользователь с указанным email уже существует")) self.add_error('email', _("Пользователь с указанным email уже существует"))

View File

@@ -239,7 +239,8 @@ def change_profile_confirm_ajax(request):
kwargs = { kwargs = {
'not_required_password': True, 'not_required_password': True,
'not_required_agreement': True, 'not_required_agreement': True,
'not_required_email': True 'not_required_email': True,
'create_new_account': False,
} }
form = RegistrationForm(data, **kwargs) form = RegistrationForm(data, **kwargs)
if not form.is_valid(): if not form.is_valid():