Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms: Normalized all error <ul>s to use class='errorlist'

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4120 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 190c987e631efeebfab5892aef9a980963cfab7e 1 parent 49236b9
Adrian Holovaty authored November 27, 2006
15  django/newforms/forms.py
@@ -76,11 +76,11 @@ def as_table(self):
76 76
         output = []
77 77
         if self.errors.get(NON_FIELD_ERRORS):
78 78
             # Errors not corresponding to a particular field are displayed at the top.
79  
-            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]]))
  79
+            output.append(u'<tr><td colspan="2">%s</td></tr>' % self.non_field_errors())
80 80
         for name, field in self.fields.items():
81 81
             bf = BoundField(self, field, name)
82 82
             if bf.errors:
83  
-                output.append(u'<tr><td colspan="2"><ul>%s</ul></td></tr>' % u'\n'.join([u'<li>%s</li>' % e for e in bf.errors]))
  83
+                output.append(u'<tr><td colspan="2">%s</td></tr>' % bf.errors)
84 84
             output.append(u'<tr><td>%s:</td><td>%s</td></tr>' % (bf.label, bf))
85 85
         return u'\n'.join(output)
86 86
 
@@ -89,22 +89,23 @@ def as_ul(self):
89 89
         output = []
90 90
         if self.errors.get(NON_FIELD_ERRORS):
91 91
             # Errors not corresponding to a particular field are displayed at the top.
92  
-            output.append(u'<li><ul>%s</ul></li>' % u'\n'.join([u'<li>%s</li>' % e for e in self.errors[NON_FIELD_ERRORS]]))
  92
+            output.append(u'<li>%s</li>' % self.non_field_errors())
93 93
         for name, field in self.fields.items():
94 94
             bf = BoundField(self, field, name)
95 95
             line = u'<li>'
96 96
             if bf.errors:
97  
-                line += u'<ul>%s</ul>' % u'\n'.join([u'<li>%s</li>' % e for e in bf.errors])
  97
+                line += str(bf.errors)
98 98
             line += u'%s: %s</li>' % (bf.label, bf)
99 99
             output.append(line)
100 100
         return u'\n'.join(output)
101 101
 
102 102
     def non_field_errors(self):
103 103
         """
104  
-        Returns a list of errors that aren't associated with a particular
105  
-        field -- i.e., from Form.clean().
  104
+        Returns an ErrorList of errors that aren't associated with a particular
  105
+        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
  106
+        are none.
106 107
         """
107  
-        return self.errors.get(NON_FIELD_ERRORS, [])
  108
+        return self.errors.get(NON_FIELD_ERRORS, ErrorList())
108 109
 
109 110
     def full_clean(self):
110 111
         """
32  tests/regressiontests/forms/tests.py
@@ -1173,23 +1173,23 @@
1173 1173
 >>> p.is_valid()
1174 1174
 False
1175 1175
 >>> print p
1176  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1176
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1177 1177
 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr>
1178  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1178
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1179 1179
 <tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr>
1180  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1180
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1181 1181
 <tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr>
1182 1182
 >>> print p.as_table()
1183  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1183
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1184 1184
 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr>
1185  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1185
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1186 1186
 <tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr>
1187  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1187
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1188 1188
 <tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr>
1189 1189
 >>> print p.as_ul()
1190  
-<li><ul><li>This field is required.</li></ul>First name: <input type="text" name="first_name" /></li>
1191  
-<li><ul><li>This field is required.</li></ul>Last name: <input type="text" name="last_name" /></li>
1192  
-<li><ul><li>This field is required.</li></ul>Birthday: <input type="text" name="birthday" /></li>
  1190
+<li><ul class="errorlist"><li>This field is required.</li></ul>First name: <input type="text" name="first_name" /></li>
  1191
+<li><ul class="errorlist"><li>This field is required.</li></ul>Last name: <input type="text" name="last_name" /></li>
  1192
+<li><ul class="errorlist"><li>This field is required.</li></ul>Birthday: <input type="text" name="birthday" /></li>
1193 1193
 
1194 1194
 If you don't pass any values to the Form's __init__(), or if you pass None,
1195 1195
 the Form won't do any validation. Form.errors will be an empty dictionary *but*
@@ -1445,11 +1445,11 @@
1445 1445
 {}
1446 1446
 >>> f = UserRegistration({})
1447 1447
 >>> print f.as_table()
1448  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1448
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1449 1449
 <tr><td>Username:</td><td><input type="text" name="username" /></td></tr>
1450  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1450
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1451 1451
 <tr><td>Password1:</td><td><input type="password" name="password1" /></td></tr>
1452  
-<tr><td colspan="2"><ul><li>This field is required.</li></ul></td></tr>
  1452
+<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr>
1453 1453
 <tr><td>Password2:</td><td><input type="password" name="password2" /></td></tr>
1454 1454
 >>> f.errors
1455 1455
 {'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']}
@@ -1457,12 +1457,12 @@
1457 1457
 >>> f.errors
1458 1458
 {'__all__': [u'Please make sure your passwords match.']}
1459 1459
 >>> print f.as_table()
1460  
-<tr><td colspan="2"><ul><li>Please make sure your passwords match.</li></ul></td></tr>
  1460
+<tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr>
1461 1461
 <tr><td>Username:</td><td><input type="text" name="username" value="adrian" /></td></tr>
1462 1462
 <tr><td>Password1:</td><td><input type="password" name="password1" value="foo" /></td></tr>
1463 1463
 <tr><td>Password2:</td><td><input type="password" name="password2" value="bar" /></td></tr>
1464 1464
 >>> print f.as_ul()
1465  
-<li><ul><li>Please make sure your passwords match.</li></ul></li>
  1465
+<li><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></li>
1466 1466
 <li>Username: <input type="text" name="username" value="adrian" /></li>
1467 1467
 <li>Password1: <input type="password" name="password1" value="foo" /></li>
1468 1468
 <li>Password2: <input type="password" name="password2" value="bar" /></li>
@@ -1556,8 +1556,8 @@
1556 1556
 >>> print my_function('POST', {'username': 'this-is-a-long-username', 'password1': 'foo', 'password2': 'bar'})
1557 1557
 <form action="" method="post">
1558 1558
 <table>
1559  
-<tr><td colspan="2"><ul><li>Please make sure your passwords match.</li></ul></td></tr>
1560  
-<tr><td colspan="2"><ul><li>Ensure this value has at most 10 characters.</li></ul></td></tr>
  1559
+<tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr>
  1560
+<tr><td colspan="2"><ul class="errorlist"><li>Ensure this value has at most 10 characters.</li></ul></td></tr>
1561 1561
 <tr><td>Username:</td><td><input type="text" name="username" value="this-is-a-long-username" /></td></tr>
1562 1562
 <tr><td>Password1:</td><td><input type="password" name="password1" value="foo" /></td></tr>
1563 1563
 <tr><td>Password2:</td><td><input type="password" name="password2" value="bar" /></td></tr>

0 notes on commit 190c987

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