diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 667ae0a472..e381bb906e 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -76,11 +76,11 @@ class Form(object): output = [] if self.errors.get(NON_FIELD_ERRORS): # Errors not corresponding to a particular field are displayed at the top. - output.append(u'' % u'\n'.join([u'
  • %s
  • ' % e for e in self.errors[NON_FIELD_ERRORS]])) + output.append(u'%s' % self.non_field_errors()) for name, field in self.fields.items(): bf = BoundField(self, field, name) if bf.errors: - output.append(u'' % u'\n'.join([u'
  • %s
  • ' % e for e in bf.errors])) + output.append(u'%s' % bf.errors) output.append(u'%s:%s' % (bf.label, bf)) return u'\n'.join(output) @@ -89,22 +89,23 @@ class Form(object): output = [] if self.errors.get(NON_FIELD_ERRORS): # Errors not corresponding to a particular field are displayed at the top. - output.append(u'
  • ' % u'\n'.join([u'
  • %s
  • ' % e for e in self.errors[NON_FIELD_ERRORS]])) + output.append(u'
  • %s
  • ' % self.non_field_errors()) for name, field in self.fields.items(): bf = BoundField(self, field, name) line = u'
  • ' if bf.errors: - line += u'' % u'\n'.join([u'
  • %s
  • ' % e for e in bf.errors]) + line += str(bf.errors) line += u'%s: %s' % (bf.label, bf) output.append(line) return u'\n'.join(output) def non_field_errors(self): """ - Returns a list of errors that aren't associated with a particular - field -- i.e., from Form.clean(). + Returns an ErrorList of errors that aren't associated with a particular + field -- i.e., from Form.clean(). Returns an empty ErrorList if there + are none. """ - return self.errors.get(NON_FIELD_ERRORS, []) + return self.errors.get(NON_FIELD_ERRORS, ErrorList()) def full_clean(self): """ diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index c7e222c7d2..8f9f0ec24d 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1173,23 +1173,23 @@ Empty dictionaries are valid, too. >>> p.is_valid() False >>> print p - + First name: - + Last name: - + Birthday: >>> print p.as_table() - + First name: - + Last name: - + Birthday: >>> print p.as_ul() -
  • First name:
  • -
  • Last name:
  • -
  • Birthday:
  • +
  • First name:
  • +
  • Last name:
  • +
  • Birthday:
  • If you don't pass any values to the Form's __init__(), or if you pass None, the Form won't do any validation. Form.errors will be an empty dictionary *but* @@ -1445,11 +1445,11 @@ Form.clean() is required to return a dictionary of all clean data. {} >>> f = UserRegistration({}) >>> print f.as_table() - + Username: - + Password1: - + Password2: >>> f.errors {'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} @@ -1457,12 +1457,12 @@ Form.clean() is required to return a dictionary of all clean data. >>> f.errors {'__all__': [u'Please make sure your passwords match.']} >>> print f.as_table() - + Username: Password1: Password2: >>> print f.as_ul() -
  • +
  • Username:
  • Password1:
  • Password2:
  • @@ -1556,8 +1556,8 @@ Case 2: POST with erroneous data (a redisplayed form, with errors). >>> print my_function('POST', {'username': 'this-is-a-long-username', 'password1': 'foo', 'password2': 'bar'})
    - - + +
    • Please make sure your passwords match.
    • Ensure this value has at most 10 characters.
    • Please make sure your passwords match.
    • Ensure this value has at most 10 characters.
    Username:
    Password1:
    Password2: