Coverage for accounts/forms.py: 100.00%
20 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 10:02 -0700
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 10:02 -0700
1from django.contrib.auth import get_user_model 1a
2from django.contrib.auth.forms import UserChangeForm, UserCreationForm 1a
3from django.core.exceptions import ValidationError 1a
5User = get_user_model() 1a
8class CustomUserChangeForm(UserChangeForm): 1a
9 class Meta: 1a
10 model = User 1a
11 fields = ( 1a
12 "email",
13 "username",
14 "profile_pic",
15 )
18class CustomUserCreationForm(UserCreationForm): 1a
19 error_message = UserCreationForm.error_messages.update( 1a
20 {"duplicate_username": "This username has already been taken."} # fmt: skip
21 )
23 class Meta: 1a
24 model = User 1a
25 fields = ( 1a
26 "email",
27 "username",
28 "profile_pic",
29 )
31 def clean_username(self): 1a
32 username = self.cleaned_data["username"] 1a
34 try: 1a
35 User.objects.get(username=username) 1a
36 except User.DoesNotExist: 1a
37 return username 1a
39 raise ValidationError(self.error_messages["duplicate_username"]) 1a