summaryrefslogtreecommitdiff
path: root/django/newforms/forms.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-11-27 01:55:24 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-11-27 01:55:24 +0000
commit682e435c5f334bc0211b12f05398fe79e4e72713 (patch)
tree01c0238c0a39ec29c76f7456450c681f7fa0011c /django/newforms/forms.py
parent48b36bb4a418e8a453eaec1c15e4a48c184e5328 (diff)
newforms: Changed Form.errors to be a property rather than a function. Refs #3026
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4116 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/forms.py')
-rw-r--r--django/newforms/forms.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index f04e04926a..f58ce2c563 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -56,19 +56,20 @@ class Form(object):
raise KeyError('Key %r not found in Form' % name)
return BoundField(self, field, name)
- def errors(self):
+ def _errors(self):
"Returns an ErrorDict for self.data"
if self.__errors is None:
self.full_clean()
return self.__errors
+ errors = property(_errors)
def is_valid(self):
"""
Returns True if the form has no errors. Otherwise, False. This exists
solely for convenience, so client code can use positive logic rather
- than confusing negative logic ("if not form.errors()").
+ than confusing negative logic ("if not form.errors").
"""
- return not bool(self.errors())
+ return not bool(self.errors)
def as_table(self):
"Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
@@ -81,9 +82,9 @@ class Form(object):
def as_table_with_errors(self):
"Returns this form rendered as HTML <tr>s, with errors."
output = []
- if self.errors().get(NON_FIELD_ERRORS):
+ if self.errors.get(NON_FIELD_ERRORS):
# Errors not corresponding to a particular field are displayed at the top.
- output.append(u'<tr><td colspan="2"><ul>%s</ul></td></tr>' % u'\n'.join([u'<li>%s</li>' % e for e in self.errors()[NON_FIELD_ERRORS]]))
+ output.append(u'<tr><td colspan="2"><ul>%s</ul></td></tr>' % u'\n'.join([u'<li>%s</li>' % e for e in self.errors[NON_FIELD_ERRORS]]))
for name, field in self.fields.items():
bf = BoundField(self, field, name)
if bf.errors:
@@ -94,9 +95,9 @@ class Form(object):
def as_ul_with_errors(self):
"Returns this form rendered as HTML <li>s, with errors."
output = []
- if self.errors().get(NON_FIELD_ERRORS):
+ if self.errors.get(NON_FIELD_ERRORS):
# Errors not corresponding to a particular field are displayed at the top.
- output.append(u'<li><ul>%s</ul></li>' % u'\n'.join([u'<li>%s</li>' % e for e in self.errors()[NON_FIELD_ERRORS]]))
+ output.append(u'<li><ul>%s</ul></li>' % u'\n'.join([u'<li>%s</li>' % e for e in self.errors[NON_FIELD_ERRORS]]))
for name, field in self.fields.items():
bf = BoundField(self, field, name)
line = u'<li>'
@@ -162,7 +163,7 @@ class BoundField(object):
if there are none.
"""
try:
- return self._form.errors()[self._name]
+ return self._form.errors[self._name]
except KeyError:
return ErrorList()
errors = property(_errors)