Ticket #6652: field-on-validation-error.patch
File field-on-validation-error.patch, 1.1 KB (added by , 17 years ago) |
---|
-
newforms/util.py
50 50 return repr([force_unicode(e) for e in self]) 51 51 52 52 class ValidationError(Exception): 53 def __init__(self, message ):53 def __init__(self, message, field=None): 54 54 """ 55 55 ValidationError can be passed any object that can be printed (usually 56 56 a string) or a list of objects. 57 57 """ 58 self.field = field 58 59 if isinstance(message, list): 59 60 self.messages = ErrorList([smart_unicode(msg) for msg in message]) 60 61 else: -
newforms/forms.py
198 198 try: 199 199 self.cleaned_data = self.clean() 200 200 except ValidationError, e: 201 self._errors[ NON_FIELD_ERRORS] = e.messages201 self._errors[e.field or NON_FIELD_ERRORS] = e.messages 202 202 if self._errors: 203 203 delattr(self, 'cleaned_data') 204 204