0.8.38 change profile validation
This commit is contained in:
@@ -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", _('Пароль и подтверждение пароля не совпадают'))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -253,7 +253,7 @@ def techSendMail_for_specified_email_list(sets, html_content, email_list, title=
|
||||
|
||||
except Exception as e:
|
||||
msg = 'techSendMail_for_specified_email_list error={0}'.format(str(e))
|
||||
techSendMail(msg)
|
||||
techSendMail(sets, msg)
|
||||
print(msg)
|
||||
|
||||
return 'Fail'
|
||||
|
||||
@@ -2,10 +2,18 @@ from django.utils.translation import gettext as _
|
||||
def get_phone_valid_error(val):
|
||||
allow_chars = '01234567890()+ -'
|
||||
|
||||
error_msg = _('Некорректные символы в номере телефона,<br> пример корректного ввода +7 925 8600100')
|
||||
|
||||
if len(val) < 10:
|
||||
return error_msg
|
||||
|
||||
if '+' in val and val[0] != '+':
|
||||
return error_msg
|
||||
|
||||
i = 0
|
||||
while i < len(val):
|
||||
if val[i] not in allow_chars:
|
||||
return _('Некорректные символы в номере телефона, пример корректного ввода +7 925 8600100')
|
||||
return error_msg
|
||||
|
||||
i += 1
|
||||
|
||||
|
||||
@@ -23,6 +23,18 @@ class RouteForm(forms.ModelForm):
|
||||
|
||||
|
||||
try:
|
||||
if 'phone' in cleaned_data and 'phone' in cleaned_data:
|
||||
from BaseModels.validators.form_field_validators import get_phone_valid_error
|
||||
error = get_phone_valid_error(cleaned_data["phone"])
|
||||
if error:
|
||||
self.add_error('phone', error)
|
||||
|
||||
if 'extra_phone' in cleaned_data and 'extra_phone' in cleaned_data:
|
||||
from BaseModels.validators.form_field_validators import get_phone_valid_error
|
||||
error = get_phone_valid_error(cleaned_data["extra_phone"])
|
||||
if error:
|
||||
self.add_error('extra_phone', error)
|
||||
|
||||
if 'departure_DT' in cleaned_data and 'arrival_DT' in cleaned_data and cleaned_data['arrival_DT'] < cleaned_data['departure_DT']:
|
||||
self.add_error('arrival_DT', _('Указана неверная дата прибытия'))
|
||||
|
||||
|
||||
@@ -78,6 +78,9 @@ def get_profile_new_route_page_html(request, data):
|
||||
if 'owner_type' in data:
|
||||
form.initial['owner_type'] = data['owner_type']
|
||||
|
||||
if request.user and request.user.is_authenticated and request.user.profile and request.user.profile.phone:
|
||||
form.initial.update({'phone': request.user.profile.phone})
|
||||
|
||||
Dict = {
|
||||
'form': form,
|
||||
'errors_off': errors_off
|
||||
|
||||
Reference in New Issue
Block a user