Mercurial > personas_backend
diff PersonasBackend/personas/forms.py @ 95:b42e3997fe58
Refactored and simplified validation logic.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 27 Mar 2008 20:17:22 -0700 |
parents | e1bfeffce0f0 |
children | 305fb3a1e0ca |
line wrap: on
line diff
--- a/PersonasBackend/personas/forms.py Thu Mar 27 19:55:37 2008 -0700 +++ b/PersonasBackend/personas/forms.py Thu Mar 27 20:17:22 2008 -0700 @@ -1,23 +1,6 @@ import django.newforms as forms from PersonasBackend.personas import models -def newforms_validator( func ): - """ - Turns a framework-independent validator that throws a ValueError - into a newforms-style validator that throws a ValidationError. - - This is needed because Django's admin interface currently uses - old-style forms. - """ - - def wrapper( *args, **kwargs ): - try: - return func( *args, **kwargs ) - except ValueError, e: - raise forms.ValidationError( e.message ) - - return wrapper - class PersonaForm( forms.ModelForm ): """ Form given to normal users who don't have the permission to @@ -41,9 +24,11 @@ "a result of hosting said content.") ) - @newforms_validator def _color_cleaner( self, field ): - models.ensure_color_is_valid( self.cleaned_data[field] ) + models.ensure_color_is_valid( + self.cleaned_data[field], + error_class = forms.ValidationError + ) return self.cleaned_data[field] def clean_text_color( self ): @@ -55,9 +40,10 @@ def clean( self ): form_data = dict( self.cleaned_data ) form_data.update( self.files ) - newforms_validator( - models.ensure_header_and_footer_are_valid - )( form_data ) + models.ensure_header_and_footer_are_valid( + form_data, + error_class = forms.ValidationError + ) if not self.cleaned_data["agree_to_terms"]: raise forms.ValidationError( "You must agree to the terms of service to "