Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserSignUpForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super(UserSignUpForm, self).__init__(*args, **kwargs)
- self.fields['email'].required = True
- self.fields['first_name'].required = True
- self.fields['last_name'].required = True
- who = forms.ChoiceField(
- choices=[('student', 'Student'), ('teacher', 'Teacher')],
- label="",
- required=True,
- widget=forms.RadioSelect(
- attrs={'style':'max-width: 20em; ', 'autocomplete':'off', })
- )
- password = forms.CharField(
- label="Password",
- help_text="Your password must contain at least 8 characters and can’t be entirely numeric.",
- validators=[MinLengthValidator(8, message="Minimum 8 characters"),],
- widget=forms.PasswordInput(attrs={'autocomplete':'off'}))
- confirm_password = forms.CharField(
- label="Confirm password",
- validators=[MinLengthValidator(8, message="Minimum 8 characters"), ],
- widget=forms.PasswordInput(attrs={'autocomplete':'off'}))
- class Meta:
- model = User
- fields = ('who', 'username', 'email', 'first_name', 'last_name', 'password', )
- help_texts = {"password": None}
- widgets = {
- 'username': forms.TextInput(attrs={}),
- 'first_name': forms.TextInput(attrs={}),
- 'last_name': forms.TextInput(attrs={}),
- 'email': forms.TextInput(attrs={}),
- }
- def clean(self):
- cleaned_data = super(UserSignUpForm, self).clean()
- password = cleaned_data.get("password")
- NumericPasswordValidator(password)
- confirm_password = cleaned_data.get("confirm_password")
- if password != confirm_password:
- msg = _(f'Password and confirm password does not match')
- self.add_error('password', msg)
- self.add_error('confirm_password', msg)
- helper = FormHelper()
- helper.form_tag = 'false'
- helper.attrs = {"novalidate": True, 'autocomplete':'off'}
- helper.form_class = 'form-horizontal'
- helper.field_class = 'col-md-7 '
- helper.label_class = 'col-md-5'
- helper.layout = Layout(
- Row(
- Column(
- Field('who', css_class='form-group', style='margin-left:200px'),
- Field('username', css_class='form-group ', style=''),
- Field('email', css_class='form-group'),
- Field('first_name', css_class='form-group'),
- Field('last_name', css_class='form-group'),
- Field('password', css_class='form-group'),
- Field('confirm_password', css_class='form-group'),
- FormActions(
- Submit('save', 'Sign up', css_class="btn-primary"),
- ),
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement