1
0
mirror of https://github.com/django/django.git synced 2024-12-25 18:46:22 +00:00

Fixed #3718 -- Exposed form errors to cleaning methods as soon as they are

available. Patch from Gary Wilson.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5348 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-05-26 09:02:17 +00:00
parent 1c42c7cade
commit a901b44c15

View File

@ -174,9 +174,8 @@ class BaseForm(StrAndUnicode):
Cleans all of self.data and populates self._errors and Cleans all of self.data and populates self._errors and
self.cleaned_data. self.cleaned_data.
""" """
errors = ErrorDict() self._errors = ErrorDict()
if not self.is_bound: # Stop further processing. if not self.is_bound: # Stop further processing.
self._errors = errors
return return
self.cleaned_data = {} self.cleaned_data = {}
for name, field in self.fields.items(): for name, field in self.fields.items():
@ -191,16 +190,15 @@ class BaseForm(StrAndUnicode):
value = getattr(self, 'clean_%s' % name)() value = getattr(self, 'clean_%s' % name)()
self.cleaned_data[name] = value self.cleaned_data[name] = value
except ValidationError, e: except ValidationError, e:
errors[name] = e.messages self._errors[name] = e.messages
if name in self.cleaned_data: if name in self.cleaned_data:
del self.cleaned_data[name] del self.cleaned_data[name]
try: try:
self.cleaned_data = self.clean() self.cleaned_data = self.clean()
except ValidationError, e: except ValidationError, e:
errors[NON_FIELD_ERRORS] = e.messages self._errors[NON_FIELD_ERRORS] = e.messages
if errors: if self._errors:
delattr(self, 'cleaned_data') delattr(self, 'cleaned_data')
self._errors = errors
def clean(self): def clean(self):
""" """