forked from pythonprobr/pythonpro-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
23 lines (17 loc) · 772 Bytes
/
forms.py
File metadata and controls
23 lines (17 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django.core.exceptions import ValidationError
from django.forms import CharField, ModelForm
from django.utils.translation import gettext_lazy as _
from pythonpro.core.models import User
class UserEmailForm(ModelForm):
current_password = CharField(label=_("Password"), strip=False, required=True)
class Meta:
model = User
fields = ('email',)
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user')
super().__init__(*args, **kwargs)
def clean(self):
cleaned_data = super().clean()
if not self.user.check_password(cleaned_data.get('current_password', '')):
self.add_error('current_password', ValidationError('Senha Inválida', 'invalid_password'))
return cleaned_data