1- from django .contrib .auth .forms import UserCreationForm , UserChangeForm
2- from django .contrib .auth .models import User
31from django import forms
4- from django .contrib .auth .forms import AuthenticationForm
5-
2+ from django .contrib .auth .forms import UserCreationForm , AuthenticationForm
3+ from django .contrib .auth .models import User
4+ from django .utils .translation import gettext_lazy as _
65
76
87class UserRegisterForm (UserCreationForm ):
8+ first_name = forms .CharField (
9+ label = _ ("Имя" ),
10+ max_length = 30 ,
11+ widget = forms .TextInput (attrs = {'placeholder' : 'Введите имя' }),
12+ help_text = _ ('Введите ваше имя' )
13+ )
14+ last_name = forms .CharField (
15+ label = _ ("Фамилия" ),
16+ max_length = 30 ,
17+ widget = forms .TextInput (attrs = {'placeholder' : 'Введите фамилию' }),
18+ help_text = _ ('Введите вашу фамилию' )
19+ )
20+ username = forms .CharField (
21+ label = _ ("Имя пользователя" ),
22+ max_length = 150 ,
23+ widget = forms .TextInput (attrs = {'placeholder' : 'Введите имя пользователя' }),
24+ help_text = _ ('Обязательное поле. Не более 150 символов. Только буквы, цифры и символы @/./+/-/_' )
25+ )
26+ password1 = forms .CharField (
27+ label = _ ("Пароль" ),
28+ strip = False ,
29+ widget = forms .PasswordInput (attrs = {'placeholder' : 'Введите пароль' }),
30+ help_text = _ ("Ваш пароль должен содержать не менее 3 символов." )
31+ )
32+ password2 = forms .CharField (
33+ label = _ ("Подтверждение пароля" ),
34+ strip = False ,
35+ widget = forms .PasswordInput (attrs = {'placeholder' : 'Подтвердите пароль' }),
36+ help_text = _ ("Введите тот же пароль, что и выше, для проверки." )
37+ )
38+
939 class Meta :
1040 model = User
11- fields = ('username' , ' first_name' , ' last_name' , 'email' )
41+ fields = (" first_name" , " last_name" , "username" , "password1" , "password2" )
1242
13- class UserUpdateForm (UserChangeForm ):
14- password = None # не показываем поле пароля для редактирования
43+ def clean_password1 (self ):
44+ password1 = self .cleaned_data .get ("password1" )
45+ if len (password1 ) < 3 :
46+ raise ValidationError (_ ("Пароль должен содержать не менее 3 символов." ))
47+ return password1
48+
49+ class UserUpdateForm (forms .ModelForm ):
50+ first_name = forms .CharField (
51+ label = "Имя" ,
52+ max_length = 30 ,
53+ widget = forms .TextInput (attrs = {'placeholder' : 'Введите имя' }),
54+ help_text = 'Введите ваше имя'
55+ )
56+ # last_name = forms.CharField(
57+ # label="Фамилия",
58+ # max_length=30,
59+ # widget=forms.TextInput(attrs={'placeholder': 'Введите фамилию'}),
60+ # help_text='Введите вашу фамилию'
61+ # )
62+ # username = forms.CharField(
63+ # label="Имя пользователя",
64+ # max_length=150,
65+ # widget=forms.TextInput(attrs={'placeholder': 'Введите имя пользователя'}),
66+ # help_text='Обязательное поле. Не более 150 символов. Только буквы, цифры и символы @/./+/-/_'
67+ # )
1568
1669 class Meta :
1770 model = User
18- fields = ('username' , 'first_name' , 'last_name' , 'email' )
19-
71+ fields = ("first_name" , "last_name" , "username" )
2072
2173class CustomAuthenticationForm (AuthenticationForm ):
2274 username = forms .CharField (
23- widget = forms .TextInput (attrs = {"placeholder" : "Имя пользователя" })
75+ label = "Имя пользователя" ,
76+ widget = forms .TextInput (attrs = {
77+ 'autofocus' : True ,
78+ 'placeholder' : 'Введите имя пользователя'
79+ })
2480 )
2581 password = forms .CharField (
26- widget = forms .PasswordInput (attrs = {"placeholder" : "Пароль" })
27- )
28-
82+ label = "Пароль" ,
83+ strip = False ,
84+ widget = forms .PasswordInput (attrs = {
85+ 'placeholder' : 'Введите пароль'
86+ }),
87+ )
0 commit comments