Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit c50d333c23a3c53d05623ce15df79e624c57f37c 1 parent 545ebf4
Adrian Holovaty authored December 07, 2006

Showing 1 changed file with 6 additions and 10 deletions. Show diff stats Hide diff stats

  1. 16  django/newforms/forms.py
16  django/newforms/forms.py
@@ -84,13 +84,9 @@ def _html_output(self, normal_row, error_row, row_ender, errors_on_separate_row)
84 84
                     top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors])
85 85
                 hidden_fields.append(unicode(bf))
86 86
             else:
87  
-                label = bf.label_tag(escape(bf.verbose_name+':'))
88  
-                if errors_on_separate_row:
89  
-                    if bf_errors:
90  
-                        output.append(error_row % bf_errors)
91  
-                    output.append(normal_row % (label, bf))
92  
-                else:
93  
-                    output.append(normal_row % ((bf_errors, label, bf)))
  87
+                if errors_on_separate_row and bf_errors:
  88
+                    output.append(error_row % bf_errors)
  89
+                output.append(normal_row % {'errors': bf_errors, 'label': bf.label_tag(escape(bf.verbose_name+':')), 'field': bf})
94 90
         if top_errors:
95 91
             output.insert(0, error_row % top_errors)
96 92
         if hidden_fields: # Insert any hidden fields in the last row.
@@ -105,15 +101,15 @@ def _html_output(self, normal_row, error_row, row_ender, errors_on_separate_row)
105 101
 
106 102
     def as_table(self):
107 103
         "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
108  
-        return self._html_output(u'<tr><td>%s</td><td>%s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', True)
  104
+        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)
109 105
 
110 106
     def as_ul(self):
111 107
         "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
112  
-        return self._html_output(u'<li>%s%s %s</li>', u'<li>%s</li>', '</li>', False)
  108
+        return self._html_output(u'<li>%(errors)s%(label)s %(field)s</li>', u'<li>%s</li>', '</li>', False)
113 109
 
114 110
     def as_p(self):
115 111
         "Returns this form rendered as HTML <p>s."
116  
-        return self._html_output(u'<p>%s %s</p>', u'<p>%s</p>', '</p>', True)
  112
+        return self._html_output(u'<p>%(label)s %(field)s</p>', u'<p>%s</p>', '</p>', True)
117 113
 
118 114
     def non_field_errors(self):
119 115
         """

0 notes on commit c50d333

Please sign in to comment.
Something went wrong with that request. Please try again.