diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-12-07 15:49:05 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-12-07 15:49:05 +0000 |
| commit | c50d333c23a3c53d05623ce15df79e624c57f37c (patch) | |
| tree | 4f0d12e6ce89310187309f86c91d3ead3fb234b1 | |
| parent | 545ebf4395f24438c6ddc847f0794bfc83c6e934 (diff) | |
newforms: Changed Form._html_output() to use dictionary-style format strings for more flexibility. Thanks, Waylan Limberg
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4182 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/newforms/forms.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 265668bbab..e0b3d500b5 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -84,13 +84,9 @@ class Form(StrAndUnicode): top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors]) hidden_fields.append(unicode(bf)) else: - label = bf.label_tag(escape(bf.verbose_name+':')) - if errors_on_separate_row: - if bf_errors: - output.append(error_row % bf_errors) - output.append(normal_row % (label, bf)) - else: - output.append(normal_row % ((bf_errors, label, bf))) + if errors_on_separate_row and bf_errors: + output.append(error_row % bf_errors) + output.append(normal_row % {'errors': bf_errors, 'label': bf.label_tag(escape(bf.verbose_name+':')), 'field': bf}) if top_errors: output.insert(0, error_row % top_errors) if hidden_fields: # Insert any hidden fields in the last row. @@ -105,15 +101,15 @@ class Form(StrAndUnicode): def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." - return self._html_output(u'<tr><td>%s</td><td>%s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', True) + return self._html_output(u'<tr><td>%(label)s</td><td>%(field)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', True) def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." - return self._html_output(u'<li>%s%s %s</li>', u'<li>%s</li>', '</li>', False) + return self._html_output(u'<li>%(errors)s%(label)s %(field)s</li>', u'<li>%s</li>', '</li>', False) def as_p(self): "Returns this form rendered as HTML <p>s." - return self._html_output(u'<p>%s %s</p>', u'<p>%s</p>', '</p>', True) + return self._html_output(u'<p>%(label)s %(field)s</p>', u'<p>%s</p>', '</p>', True) def non_field_errors(self): """ |
