From c50d333c23a3c53d05623ce15df79e624c57f37c Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Thu, 7 Dec 2006 15:49:05 +0000 Subject: [PATCH] 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 --- django/newforms/forms.py | 16 ++++++---------- 1 file 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 s -- excluding the
." - return self._html_output(u'%s%s', u'%s', '', True) + return self._html_output(u'%(label)s%(field)s', u'%s', '', True) def as_ul(self): "Returns this form rendered as HTML
  • s -- excluding the ." - return self._html_output(u'
  • %s%s %s
  • ', u'
  • %s
  • ', '', False) + return self._html_output(u'
  • %(errors)s%(label)s %(field)s
  • ', u'
  • %s
  • ', '', False) def as_p(self): "Returns this form rendered as HTML

    s." - return self._html_output(u'

    %s %s

    ', u'

    %s

    ', '

    ', True) + return self._html_output(u'

    %(label)s %(field)s

    ', u'

    %s

    ', '

    ', True) def non_field_errors(self): """