Skip to content

Commit

Permalink
Fixed #4297 -- Made form errors available to sub-classes. Thanks, Gar…
Browse files Browse the repository at this point in the history
…y Wilson.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5347 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed May 26, 2007
1 parent 198127a commit 1c42c7c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions django/newforms/forms.py
Expand Up @@ -63,7 +63,7 @@ def __init__(self, data=None, auto_id='id_%s', prefix=None, initial=None):
self.auto_id = auto_id
self.prefix = prefix
self.initial = initial or {}
self.__errors = None # Stores the errors after clean() has been called.
self._errors = None # Stores the errors after clean() has been called.

# The base_fields class attribute is the *class-wide* definition of
# fields. Because a particular *instance* of the class might want to
Expand All @@ -87,12 +87,12 @@ def __getitem__(self, name):
raise KeyError('Key %r not found in Form' % name)
return BoundField(self, field, name)

def _errors(self):
def _get_errors(self):
"Returns an ErrorDict for self.data"
if self.__errors is None:
if self._errors is None:
self.full_clean()
return self.__errors
errors = property(_errors)
return self._errors
errors = property(_get_errors)

def is_valid(self):
"""
Expand Down Expand Up @@ -171,11 +171,12 @@ def non_field_errors(self):

def full_clean(self):
"""
Cleans all of self.data and populates self.__errors and self.cleaned_data.
Cleans all of self.data and populates self._errors and
self.cleaned_data.
"""
errors = ErrorDict()
if not self.is_bound: # Stop further processing.
self.__errors = errors
self._errors = errors
return
self.cleaned_data = {}
for name, field in self.fields.items():
Expand All @@ -199,7 +200,7 @@ def full_clean(self):
errors[NON_FIELD_ERRORS] = e.messages
if errors:
delattr(self, 'cleaned_data')
self.__errors = errors
self._errors = errors

def clean(self):
"""
Expand Down

0 comments on commit 1c42c7c

Please sign in to comment.