render_to edit_password html def edit_password request if request meth

 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
@render_to('edit_password.html')
def edit_password(request):
if request.method == 'POST':
form = EditPasswordForm(request, request.POST)
if form.is_valid():
pass
else:
return {'form': form}
form = EditPasswordForm(request)
return {'form': form}
class EditPasswordForm(forms.Form):
def __init__(self, request, *args, **kwargs):
self.request = request
assert False, self.request
super(EditPasswordForm, self).__init__(*args, **kwargs)
old_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
new_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
new_password_confirmation = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
def clean(self):
if not check_password(self.request.user, self.cleaned_data['old_password']):
raise forms.ValidationError(u"Old password isnt correct")
if self.cleaned_data['new_password'] != self.cleaned_data['new_password_confirmation']:
raise forms.ValidationError(u"password didnt match")
return self.cleaned_data