summaryrefslogtreecommitdiff
path: root/django/newforms/forms.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-11-30 17:07:40 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-11-30 17:07:40 +0000
commite130031fd2e1fa6946e56c73efab0c3ac67ebaea (patch)
tree9ea97a610e069c8359a035da520d393ac4186421 /django/newforms/forms.py
parent4dca65cdfc1e206fac323bd8afae9ae1fccc9dac (diff)
Fixed #3082 -- newforms: Changed Form as_table() and as_ul() not to display verbose names for hidden fields, and to add field-name prefix to error messages to avoid user confusion. Also added unit tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4146 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/forms.py')
-rw-r--r--django/newforms/forms.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 393f576dca..4bc6173249 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -80,9 +80,15 @@ class Form(object):
output.append(u'<tr><td colspan="2">%s</td></tr>' % self.non_field_errors())
for name, field in self.fields.items():
bf = BoundField(self, field, name)
- if bf.errors:
- output.append(u'<tr><td colspan="2">%s</td></tr>' % bf.errors)
- output.append(u'<tr><td>%s</td><td>%s</td></tr>' % (bf.label_tag(escape(bf.verbose_name+':')), bf))
+ if bf.is_hidden:
+ if bf.errors:
+ new_errors = ErrorList(['(Hidden field %s) %s' % (name, e) for e in bf.errors])
+ output.append(u'<tr><td colspan="2">%s</td></tr>' % new_errors)
+ output.append(str(bf))
+ else:
+ if bf.errors:
+ output.append(u'<tr><td colspan="2">%s</td></tr>' % bf.errors)
+ output.append(u'<tr><td>%s</td><td>%s</td></tr>' % (bf.label_tag(escape(bf.verbose_name+':')), bf))
return u'\n'.join(output)
def as_ul(self):
@@ -93,11 +99,13 @@ class Form(object):
output.append(u'<li>%s</li>' % self.non_field_errors())
for name, field in self.fields.items():
bf = BoundField(self, field, name)
- line = u'<li>'
- if bf.errors:
- line += str(bf.errors)
- line += u'%s %s</li>' % (bf.label_tag(escape(bf.verbose_name+':')), bf)
- output.append(line)
+ if bf.is_hidden:
+ if bf.errors:
+ new_errors = ErrorList(['(Hidden field %s) %s' % (name, e) for e in bf.errors])
+ output.append(u'<li>%s</li>' % new_errors)
+ output.append(str(bf))
+ else:
+ output.append(u'<li>%s%s %s</li>' % (bf.errors, bf.label_tag(escape(bf.verbose_name+':')), bf))
return u'\n'.join(output)
def non_field_errors(self):
@@ -222,6 +230,11 @@ class BoundField(object):
contents = '<label for="%s">%s</label>' % (widget.id_for_label(id_), contents)
return contents
+ def _is_hidden(self):
+ "Returns True if this BoundField's widget is hidden."
+ return self._field.widget.is_hidden
+ is_hidden = property(_is_hidden)
+
def _auto_id(self):
"""
Calculates and returns the ID attribute for this BoundField, if the