Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. class RegisterForm(forms.Form):
  2.     user_name = forms.CharField(label="Имя пользователя", min_length=2, max_length=50)
  3.     user_email = forms.EmailField(label="Email")
  4.     user_password = forms.CharField(label="Пароль", widget=forms.PasswordInput)
  5.     confirm_user_password = forms.CharField(label="Подтвердите пароль", widget=forms.PasswordInput)
  6.  
  7.     def clean_username(self):
  8.         username = self.cleaned_data.get("user_name")
  9.         if User.objects.filter(username=username).exists():
  10.             raise forms.ValidationError("Имя пользователя уже занято")
  11.         return username
  12.  
  13.     def clean_password(self):
  14.         user_password = self.cleaned_data.get("user_password")
  15.         confirm_user_password = self.cleaned_data.get("confirm_user_password")
  16.         if user_password != confirm_user_password:
  17.             raise forms.ValidationError("Пароли не совпадают")
  18.         return user_password
  19.  
  20.     def clean_email(self):
  21.         email = self.cleaned_data.get("user_email")
  22.         if User.objects.filter(email=email).exists():
  23.             raise forms.ValidationError("Этот email уже занят")
  24.         return email
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement