class PasswordField CustomField forms CharField User password def __in

 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
class PasswordField(CustomField(forms.CharField, User, 'password')):
def __init__(self, *args, **kwargs):
super(PasswordField, self).__init__(*args, **kwargs)
self.widget = forms.PasswordInput()
class PassWidget(forms.MultiWidget):
def __init__(self, *args, **kwargs):
widgets = (
forms.PasswordInput(),
forms.PasswordInput())
super(PassWidget, self).__init__(widgets, *args, **kwargs)
def decompress(self, value):
if value:
return value
return ['', '']
def format_output(self, widgets):
return '   '.join(widgets)
class PassField(forms.MultiValueField):
def __init__(self, *args, **kwargs):
fields = (
PasswordField(),
PasswordField())
super(PassField, self).__init__(*args, **kwargs)
self.label = 'Пароль'
self.widget = PassWidget()
self.help_text = 'Введите пароль и подтверждение'
def clean(self, value):
super(PassField, self).clean(value)
if value[0] != value[1]:
raise forms.ValidationError('Пароли не совпадают')
def compress(self, data_list):
if data_list:
return data_list[0]
return None