Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

from django import forms 

from django.contrib.auth.models import User 

from django.contrib.auth.forms import UserCreationForm 

from django.core.exceptions import ValidationError 

from Home.models import ProfilePic 

 

 

class UserLoginForm(forms.Form): 

"""Form to be used to log user in""" 

username = forms.CharField() 

password = forms.CharField(widget=forms.PasswordInput) 

 

 

class ProfilePicForm(forms.Form): 

"""Form that is used to update profile picture 

of the user 

""" 

class Meta: 

model=ProfilePic 

fields = ['avatar'] 

 

class UserRegistrationForm(UserCreationForm): 

"""Form to be used to register a user""" 

password1 = forms.CharField( 

label="Password", 

widget=forms.PasswordInput, 

) 

password2 = forms.CharField( 

label="Password Confirmation", 

widget=forms.PasswordInput, 

) 

 

def __init__(self, *args, **kwargs): 

super(UserRegistrationForm, self).__init__(*args, **kwargs) 

self.fields['email'].required = True 

 

class Meta: 

"""Specify fields you want to expose here""" 

model = User 

fields = ['email', 'username', 'password1', 'password2'] 

 

def clean_email(self): 

email = self.cleaned_data.get('email') 

username = self.cleaned_data.get('username') 

if User.objects.filter(email=email).exclude(username=username): 

raise forms.ValidationError(u'This email address is already taken') 

return email 

 

def clean_password2(self): 

password1 = self.cleaned_data.get('password1') 

password2 = self.cleaned_data.get('password2') 

 

if not password1 or not password2: 

raise ValidationError("Please confirm your passwrod") 

 

if password1 != password2: 

raise ValidationError("Password are not the same")