Coverage for account/forms.py: 0.00%
36 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-13 17:07 -0700
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-13 17:07 -0700
1from django import forms
2from django.contrib.auth.models import User
4from .models import Profile
7class LoginForm(forms.Form):
8 username = forms.CharField()
9 password = forms.CharField(widget=forms.PasswordInput)
12class UserRegistrationForm(forms.ModelForm):
13 password = forms.CharField(label="Password", widget=forms.PasswordInput)
14 password2 = forms.CharField(label="Repeat password", widget=forms.PasswordInput)
16 class Meta:
17 model = User
18 fields = ["username", "first_name", "email"]
20 def clean_password2(self):
21 cd = self.cleaned_data
22 if cd["password"] != cd["password2"]:
23 raise forms.ValidationError("Passwords don't match.")
24 return cd["password2"]
26 def clean_email(self):
27 data = self.cleaned_data["email"]
28 if User.objects.filter(email=data).exists():
29 raise forms.ValidationError("Email already in use.")
30 return data
33class UserEditForm(forms.ModelForm):
34 class Meta:
35 model = User
36 fields = ["first_name", "last_name", "email"]
38 def clean_email(self):
39 data = self.cleaned_data["email"]
40 qs = User.objects.exclude(id=self.instance.id).filter(email=data)
41 if qs.exists():
42 raise forms.ValidationError(" Email already in use.")
43 return data
46class ProfileEditForm(forms.ModelForm):
47 class Meta:
48 model = Profile
49 fields = ["date_of_birth", "photo"]