Skip to content

Commit 4229a7b

Browse files
committed
fix create-user
1 parent 89f5435 commit 4229a7b

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

task_manager/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.contrib import admin
22
from django.urls import path, include
33
from django.views.generic import TemplateView
4-
from task_manager.views import UserLoginView, register_view, UserLogoutView
4+
from task_manager.views import UserLoginView, UserLogoutView
55

66
urlpatterns = [
77
path('admin/', admin.site.urls),

task_manager/users/forms.py

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,87 @@
1-
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
2-
from django.contrib.auth.models import User
31
from 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

87
class 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

2173
class 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+
)

task_manager/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.contrib import messages
1313

1414

15+
1516
# def home_view(request):
1617
# return render(request, 'index.html')
1718
#

0 commit comments

Comments
 (0)