diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 6859ba2a37..2730bfe4e4 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -64,17 +64,15 @@ class Form(object):
return not bool(self.errors())
def as_table(self):
- "Returns this form rendered as an HTML
."
- output = u'\n'.join(['
%s:
%s
' % (pretty_name(name), BoundField(self, field, name)) for name, field in self.fields.items()])
- return '
\n%s\n
' % output
+ "Returns this form rendered as HTML
s -- excluding the
."
+ return u'\n'.join(['
%s:
%s
' % (pretty_name(name), BoundField(self, field, name)) for name, field in self.fields.items()])
def as_ul(self):
- "Returns this form rendered as an HTML
."
- output = u'\n'.join(['
%s: %s
' % (pretty_name(name), BoundField(self, field, name)) for name, field in self.fields.items()])
- return '
\n%s\n
' % output
+ "Returns this form rendered as HTML
s -- excluding the
."
+ return u'\n'.join(['
%s: %s
' % (pretty_name(name), BoundField(self, field, name)) for name, field in self.fields.items()])
def as_table_with_errors(self):
- "Returns this form rendered as an HTML
, with errors."
+ "Returns this form rendered as HTML
s, with errors."
output = []
if self.errors().get(NON_FIELD_ERRORS):
# Errors not corresponding to a particular field are displayed at the top.
@@ -84,10 +82,10 @@ class Form(object):
if bf.errors:
output.append('
%s
' % '\n'.join(['
%s
' % e for e in bf.errors]))
output.append('
%s:
%s
' % (pretty_name(name), bf))
- return '
\n%s\n
' % '\n'.join(output)
+ return u'\n'.join(output)
def as_ul_with_errors(self):
- "Returns this form rendered as an HTML
, with errors."
+ "Returns this form rendered as HTML
s, with errors."
output = []
if self.errors().get(NON_FIELD_ERRORS):
# Errors not corresponding to a particular field are displayed at the top.
@@ -99,7 +97,7 @@ class Form(object):
line += '
%s
' % '\n'.join(['
%s
' % e for e in bf.errors])
line += '%s: %s' % (pretty_name(name), bf)
output.append(line)
- return '
\n%s\n
' % '\n'.join(output)
+ return u'\n'.join(output)
def full_clean(self):
"""
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index e63ca097f7..b02ccb8ee8 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -881,38 +881,28 @@ ValidationError: [u'This field is required.']
... birthday = DateField()
>>> p = Person()
>>> 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:
-
>>> print p.as_table_with_errors()
-
This field is required.
First name:
This field is required.
Last name:
This field is required.
Birthday:
-
>>> print p.as_ul_with_errors()
-
This field is required.
First name:
This field is required.
Last name:
This field is required.
Birthday:
-
>>> p = Person({'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9'})
>>> p.errors()
@@ -937,11 +927,9 @@ u''
>>> print p
-
First name:
Last name:
Birthday:
-
>>> p = Person({'last_name': u'Lennon'})
>>> p.errors()
@@ -978,31 +966,25 @@ If it's a string that contains '%s', Django will use that as a format string
into which the field's name will be inserted.
>>> p = Person(auto_id='id_%s')
>>> print p.as_ul()
-
First name:
Last name:
Birthday:
-
If auto_id is any True value whose str() does not contain '%s', the "id"
attribute will be the name of the field.
>>> p = Person(auto_id=True)
>>> print p.as_ul()
-
First name:
Last name:
Birthday:
-
If auto_id is any False value, an "id" attribute won't be output unless it
was manually entered.
>>> p = Person(auto_id=False)
>>> print p.as_ul()
-
First name:
Last name:
Birthday:
-
In this example, auto_id is False, but the "id" attribute for the "first_name"
field is given.
@@ -1012,21 +994,17 @@ field is given.
... birthday = DateField()
>>> p = PersonNew(auto_id=False)
>>> print p.as_ul()
-
First name:
Last name:
Birthday:
-
If the "id" attribute is specified in the Form and auto_id is True, the "id"
attribute in the Form gets precedence.
>>> p = PersonNew(auto_id=True)
>>> print p.as_ul()
-
First name:
Last name:
Birthday:
-
>>> class SignupForm(Form):
... email = EmailField()
@@ -1158,36 +1136,28 @@ Form.clean() still needs to return a dictionary of all clean data:
... return self.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.']}
>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'})
>>> f.errors()
{'__all__': [u'Please make sure your passwords match.']}
>>> print f.as_table()
-
Username:
Password1:
Password2:
-
>>> print f.as_table_with_errors()
-
Please make sure your passwords match.
Username:
Password1:
Password2:
-
>>> print f.as_ul_with_errors()
-
Please make sure your passwords match.
Username:
Password1:
Password2:
-
>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'})
>>> f.errors()
{}
@@ -1205,11 +1175,9 @@ subclass' __init__().
... self.fields['birthday'] = DateField()
>>> p = Person()
>>> print p
-