Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django import forms
- from django.contrib.auth.models import User
- from django.core.validators import MinLengthValidator
- from django.utils.translation import gettext_lazy as _
- #https://docs.djangoproject.com/en/3.1/ref/forms/widgets/
- class UserSignUpForm(forms.ModelForm):
- who = forms.ChoiceField(
- choices=[('student', 'Student'), ('teacher', 'Teacher')],
- required=True,
- widget=forms.RadioSelect(
- attrs={'style':'max-width: 20em; margin:auto;' ,
- 'autocomplete':'off', })
- )
- password = forms.CharField(
- label="Password",
- validators=[MinLengthValidator(8, message="Minimum 8 characters")],
- widget=forms.PasswordInput(attrs={'style':'max-width: 20em; margin:auto', 'autocomplete':'off'}))
- confirm_password = forms.CharField(
- label="Confirm password",
- validators=[MinLengthValidator(8, message="Minimum 8 characters"), ],
- widget=forms.PasswordInput(attrs={'style':'max-width: 20em; margin:auto', 'autocomplete':'off'}))
- class Meta:
- model = User
- fields = ('who', "username", 'first_name', 'last_name', "password", )
- help_texts = {"username": None}
- widgets = {
- 'username': forms.TextInput(attrs={'style':'max-width: 20em; margin:auto'}),
- 'first_name': forms.TextInput(attrs={'style':'max-width: 20em; margin:auto'}),
- 'last_name': forms.TextInput(attrs={'style':'max-width: 20em; margin:auto'}),
- }
- def clean(self):
- cleaned_data = super(UserSignUpForm, self).clean()
- password = cleaned_data.get("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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement