mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +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:
parent
1c42c7cade
commit
a901b44c15
@ -174,9 +174,8 @@ class BaseForm(StrAndUnicode):
|
||||
Cleans all of self.data and populates self._errors and
|
||||
self.cleaned_data.
|
||||
"""
|
||||
errors = ErrorDict()
|
||||
self._errors = ErrorDict()
|
||||
if not self.is_bound: # Stop further processing.
|
||||
self._errors = errors
|
||||
return
|
||||
self.cleaned_data = {}
|
||||
for name, field in self.fields.items():
|
||||
@ -191,16 +190,15 @@ class BaseForm(StrAndUnicode):
|
||||
value = getattr(self, 'clean_%s' % name)()
|
||||
self.cleaned_data[name] = value
|
||||
except ValidationError, e:
|
||||
errors[name] = e.messages
|
||||
self._errors[name] = e.messages
|
||||
if name in self.cleaned_data:
|
||||
del self.cleaned_data[name]
|
||||
try:
|
||||
self.cleaned_data = self.clean()
|
||||
except ValidationError, e:
|
||||
errors[NON_FIELD_ERRORS] = e.messages
|
||||
if errors:
|
||||
self._errors[NON_FIELD_ERRORS] = e.messages
|
||||
if self._errors:
|
||||
delattr(self, 'cleaned_data')
|
||||
self._errors = errors
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user