refactor osusers password forms

- use PasswordModelFormMixin from gvawebcore instead of own implementation in
  ChangeOsUserPasswordForm
- change import for PASSWORD_MISMATCH_ERROR
This commit is contained in:
Jan Dittberner 2015-01-25 12:02:31 +01:00
parent 9883db6fa2
commit 2b989799ab
2 changed files with 4 additions and 30 deletions

View file

@ -6,7 +6,7 @@ from django import forms
from django.utils.translation import ugettext as _
from django.contrib import admin
from .forms import (
from gvawebcore.forms import (
PASSWORD_MISMATCH_ERROR
)
from .models import (

View file

@ -11,28 +11,16 @@ from django.utils.translation import ugettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from gvawebcore.forms import PasswordModelFormMixin
from .models import User
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
"""
Error message for non matching passwords.
"""
class ChangeOsUserPasswordForm(forms.ModelForm):
class ChangeOsUserPasswordForm(PasswordModelFormMixin, forms.ModelForm):
"""
A form for setting an OS user's password.
"""
password1 = forms.CharField(
label=_('Password'), widget=forms.PasswordInput,
required=False,
)
password2 = forms.CharField(
label=_('Password (again)'), widget=forms.PasswordInput,
required=False,
)
class Meta:
model = User
fields = []
@ -44,20 +32,6 @@ class ChangeOsUserPasswordForm(forms.ModelForm):
'set_osuser_password', kwargs={'slug': self.instance.username})
self.helper.add_input(Submit('submit', _('Set password')))
def clean_password2(self):
"""
Check that the two password entries match.
:return: the validated password
:rtype: str or None
"""
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 and password1 != password2:
raise forms.ValidationError(PASSWORD_MISMATCH_ERROR)
return password2
def save(self, commit=True):
"""
Save the provided password in hashed format.