make password a required field when restriction_type = password

pull/426/head
Matt Westcott 2014-06-06 16:53:25 +01:00
rodzic 0fbd3e7e14
commit 47c0a197c8
1 zmienionych plików z 9 dodań i 0 usunięć

Wyświetl plik

@ -83,3 +83,12 @@ class PageViewRestrictionForm(forms.Form):
('password', ugettext_lazy("This page is only viewable to users who enter this password:")),
], widget=forms.RadioSelect)
password = forms.CharField(required=False)
def clean(self):
cleaned_data = super(PageViewRestrictionForm, self).clean()
if cleaned_data.get('restriction_type') == 'password' and not cleaned_data.get('password'):
self._errors["password"] = self.error_class([_('This field is required.')])
del cleaned_data['password']
return cleaned_data