|
|
|
@ -13,11 +13,12 @@ from django.contrib.auth.forms import ( |
|
|
|
AuthenticationForm as AuthenticationFormBase, |
|
|
|
AuthenticationForm as AuthenticationFormBase, |
|
|
|
PasswordResetForm as PasswordResetFormBase, |
|
|
|
PasswordResetForm as PasswordResetFormBase, |
|
|
|
SetPasswordForm as SetPasswordFormBase, |
|
|
|
SetPasswordForm as SetPasswordFormBase, |
|
|
|
UsernameField |
|
|
|
UserChangeForm as UserChangeFormBase, |
|
|
|
|
|
|
|
UserCreationForm as UserCreationFormBase |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
from django.contrib.auth.forms import UsernameField |
|
|
|
from core.models import STATUS_ACTIVE |
|
|
|
from core.models import STATUS_ACTIVE, STATUS_CHOICES |
|
|
|
from .models import User, Profile, Company, COMPANY_STATUS_INDIVIDUAL, COMPANY_STATUS_LEGAL |
|
|
|
from .models import User, Profile, Company |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
@ -50,7 +51,7 @@ class RegistrationForm(RegistrationFormUniqueEmail): |
|
|
|
agreement = forms.BooleanField() |
|
|
|
agreement = forms.BooleanField() |
|
|
|
|
|
|
|
|
|
|
|
# captcha = CaptchaField(required=not settings.DEBUG) |
|
|
|
# captcha = CaptchaField(required=not settings.DEBUG) |
|
|
|
captcha = CaptchaField(required=False) |
|
|
|
captcha = CaptchaField(required=not settings.DEBUG) |
|
|
|
|
|
|
|
|
|
|
|
title = _('Регистрация') |
|
|
|
title = _('Регистрация') |
|
|
|
|
|
|
|
|
|
|
|
@ -75,7 +76,7 @@ class RegistrationForm(RegistrationFormUniqueEmail): |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
model = User |
|
|
|
model = User |
|
|
|
fields = ('username','email',) |
|
|
|
fields = ('username', 'email',) |
|
|
|
labels = { |
|
|
|
labels = { |
|
|
|
'username': _('Логин'), |
|
|
|
'username': _('Логин'), |
|
|
|
} |
|
|
|
} |
|
|
|
@ -92,7 +93,7 @@ class RegistrationCompanyForm(forms.ModelForm): |
|
|
|
|
|
|
|
|
|
|
|
def save(self, user, commit=True): |
|
|
|
def save(self, user, commit=True): |
|
|
|
self.instance.user = user |
|
|
|
self.instance.user = user |
|
|
|
self.instance.status = COMPANY_STATUS_INDIVIDUAL if self.cleaned_data['is_individual'] else COMPANY_STATUS_LEGAL |
|
|
|
self.instance.set_company_type(self.cleaned_data['is_individual']) |
|
|
|
return super().save(commit) |
|
|
|
return super().save(commit) |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
@ -160,7 +161,8 @@ class PasswordResetRequestForm(PasswordResetFormBase): |
|
|
|
self.helper = FormHelper() |
|
|
|
self.helper = FormHelper() |
|
|
|
self.helper.form_action = reverse_lazy('accounts_ext:reset_password') |
|
|
|
self.helper.form_action = reverse_lazy('accounts_ext:reset_password') |
|
|
|
self.helper.layout = Layout( |
|
|
|
self.helper.layout = Layout( |
|
|
|
Field('email', css_class='reg__text reg__text__center', template=self.field_template, placeholder="example@email.com"), |
|
|
|
Field('email', css_class='reg__text reg__text__center', template=self.field_template, |
|
|
|
|
|
|
|
placeholder="example@email.com"), |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Submit('submit', _('Сбросить'), css_class='btn-danger'), |
|
|
|
Submit('submit', _('Сбросить'), css_class='btn-danger'), |
|
|
|
@ -189,8 +191,10 @@ class SetPasswordForm(SetPasswordFormBase): |
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
self.helper = FormHelper() |
|
|
|
self.helper = FormHelper() |
|
|
|
self.helper.layout = Layout( |
|
|
|
self.helper.layout = Layout( |
|
|
|
Field('new_password1',css_class='reg__text reg__text__center', template=self.field_template, placeholder=_('Пароль')), |
|
|
|
Field('new_password1', css_class='reg__text reg__text__center', template=self.field_template, |
|
|
|
Field('new_password2',css_class='reg__text reg__text__center', template=self.field_template, placeholder=_('Подтверждение пароля')), |
|
|
|
placeholder=_('Пароль')), |
|
|
|
|
|
|
|
Field('new_password2', css_class='reg__text reg__text__center', template=self.field_template, |
|
|
|
|
|
|
|
placeholder=_('Подтверждение пароля')), |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Submit('submit', _('Сбросить пароль'), css_class='btn-danger'), |
|
|
|
Submit('submit', _('Сбросить пароль'), css_class='btn-danger'), |
|
|
|
@ -204,7 +208,6 @@ class SetPasswordForm(SetPasswordFormBase): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProfileForm(forms.Form): |
|
|
|
class ProfileForm(forms.Form): |
|
|
|
email = forms.CharField(required=False) |
|
|
|
|
|
|
|
field_template = 'bootstrap/field_admin.html' |
|
|
|
field_template = 'bootstrap/field_admin.html' |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
@ -215,15 +218,38 @@ class ProfileForm(forms.Form): |
|
|
|
self.helper.form_class = 'formajax form-replace-block' |
|
|
|
self.helper.form_class = 'formajax form-replace-block' |
|
|
|
self.helper.layout = Layout( |
|
|
|
self.helper.layout = Layout( |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
Field('email', template=self.field_template), |
|
|
|
|
|
|
|
Field('first_name', template=self.field_template), |
|
|
|
Field('first_name', template=self.field_template), |
|
|
|
Field('last_name', template=self.field_template), |
|
|
|
Field('last_name', template=self.field_template), |
|
|
|
Field('patronymic', template=self.field_template), |
|
|
|
Field('patronymic', template=self.field_template), |
|
|
|
Field('birthday', template=self.field_template), |
|
|
|
Field('birthday', template=self.field_template), |
|
|
|
|
|
|
|
Field('phone', template=self.field_template), |
|
|
|
|
|
|
|
css_class="setProfile" |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
Div( |
|
|
|
|
|
|
|
Submit('submit', _('Save'), css_class='button button--bigOrange'), |
|
|
|
|
|
|
|
css_class="settings-button" |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
self.fields['birthday'].widget.attrs['class'] = 'date inputText' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
|
|
model = Profile |
|
|
|
|
|
|
|
exclude = ('user', 'create_at', 'updated_at', 'status',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompanyForm(forms.Form): |
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
|
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.helper = FormHelper() |
|
|
|
|
|
|
|
self.helper.form_action = reverse('accounts_ext:update') |
|
|
|
|
|
|
|
self.helper.form_class = 'formajax form-replace-block' |
|
|
|
|
|
|
|
self.helper.layout = Layout( |
|
|
|
|
|
|
|
Div( |
|
|
|
Field('company_name', template=self.field_template), |
|
|
|
Field('company_name', template=self.field_template), |
|
|
|
Field('inn', template=self.field_template), |
|
|
|
Field('inn', template=self.field_template), |
|
|
|
Field('ogrn', template=self.field_template), |
|
|
|
Field('ogrn', template=self.field_template), |
|
|
|
Field('legal_address', template=self.field_template), |
|
|
|
Field('address', template=self.field_template), |
|
|
|
css_class="setProfile" |
|
|
|
css_class="setProfile" |
|
|
|
), |
|
|
|
), |
|
|
|
Div( |
|
|
|
Div( |
|
|
|
@ -231,17 +257,38 @@ class ProfileForm(forms.Form): |
|
|
|
css_class="settings-button" |
|
|
|
css_class="settings-button" |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
) |
|
|
|
self.initial['email'] = self.instance.user.email |
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
self.fields['email'].widget.attrs['readonly'] = True |
|
|
|
|
|
|
|
self.fields['birthday'].widget.attrs['class'] = 'date inputText' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
|
|
|
|
instance = getattr(self, 'instance', None) |
|
|
|
|
|
|
|
if instance and instance.pk: |
|
|
|
|
|
|
|
return instance.user.email |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return self.cleaned_data['email'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
model = Profile |
|
|
|
model = Company |
|
|
|
exclude = ('user', 'create_at', 'updated_at', 'status',) |
|
|
|
exclude = ('user', 'create_at', 'updated_at', 'status',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserChangeForm(UserChangeFormBase): |
|
|
|
|
|
|
|
status = forms.ChoiceField(choices=STATUS_CHOICES) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
|
|
|
|
super().__init__(*args, **kwargs) |
|
|
|
|
|
|
|
super.init_fields(self.fields) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
|
|
model = get_user_model() |
|
|
|
|
|
|
|
fields = '__all__' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserCreationForm(UserCreationFormBase): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
|
|
|
|
email = super().clean_email() |
|
|
|
|
|
|
|
if DisposableEmailChecker().is_disposable(email): |
|
|
|
|
|
|
|
raise forms.ValidationError(_('Введите email с валидными доменом')) |
|
|
|
|
|
|
|
return email |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Meta(UserCreationFormBase.Meta): |
|
|
|
|
|
|
|
model = get_user_model() |
|
|
|
|
|
|
|
fields = ('email', 'username', 'status',) |
|
|
|
|
|
|
|
field_classes = { |
|
|
|
|
|
|
|
'email': forms.EmailField, |
|
|
|
|
|
|
|
'username': UsernameField, |
|
|
|
|
|
|
|
'status': forms.ChoiceField |
|
|
|
|
|
|
|
} |
|
|
|
|