summaryrefslogtreecommitdiff
path: root/django/forms/forms.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-06-07 18:08:47 +0200
committerClaude Paroz <claude@2xlibre.net>2012-06-07 18:08:47 +0200
commit4a103086d5c67fa4fcc53c106c9fdf644c742dd8 (patch)
tree3df00600c27f6369f7561c3b8ddf2f97d2d341d9 /django/forms/forms.py
parent706fd9adc0b6587c7f96a834c757708e64fcf615 (diff)
Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and Jannis Leidel for the review.
Diffstat (limited to 'django/forms/forms.py')
-rw-r--r--django/forms/forms.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 09663d173c..22c3057c62 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -2,7 +2,7 @@
Form classes
"""
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
import copy
@@ -23,7 +23,7 @@ NON_FIELD_ERRORS = '__all__'
def pretty_name(name):
"""Converts 'first_name' to 'First name'"""
if not name:
- return u''
+ return ''
return name.replace('_', ' ').capitalize()
def get_declared_fields(bases, attrs, with_base_fields=True):
@@ -136,7 +136,7 @@ class BaseForm(StrAndUnicode):
"""
Add a 'initial' prefix for checking dynamic initial values
"""
- return u'initial-%s' % self.add_prefix(field_name)
+ return 'initial-%s' % self.add_prefix(field_name)
def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
"Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
@@ -149,7 +149,7 @@ class BaseForm(StrAndUnicode):
bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
if bf.is_hidden:
if bf_errors:
- top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
+ top_errors.extend(['(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
hidden_fields.append(unicode(bf))
else:
# Create a 'class="..."' atribute if the row should have any
@@ -175,7 +175,7 @@ class BaseForm(StrAndUnicode):
if field.help_text:
help_text = help_text_html % force_unicode(field.help_text)
else:
- help_text = u''
+ help_text = ''
output.append(normal_row % {
'errors': force_unicode(bf_errors),
@@ -189,7 +189,7 @@ class BaseForm(StrAndUnicode):
output.insert(0, error_row % force_unicode(top_errors))
if hidden_fields: # Insert any hidden fields in the last row.
- str_hidden = u''.join(hidden_fields)
+ str_hidden = ''.join(hidden_fields)
if output:
last_row = output[-1]
# Chop off the trailing row_ender (e.g. '</td></tr>') and
@@ -208,33 +208,33 @@ class BaseForm(StrAndUnicode):
# If there aren't any rows in the output, just append the
# hidden fields.
output.append(str_hidden)
- return mark_safe(u'\n'.join(output))
+ return mark_safe('\n'.join(output))
def as_table(self):
"Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
return self._html_output(
- normal_row = u'<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
- error_row = u'<tr><td colspan="2">%s</td></tr>',
- row_ender = u'</td></tr>',
- help_text_html = u'<br /><span class="helptext">%s</span>',
+ normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
+ error_row = '<tr><td colspan="2">%s</td></tr>',
+ row_ender = '</td></tr>',
+ help_text_html = '<br /><span class="helptext">%s</span>',
errors_on_separate_row = False)
def as_ul(self):
"Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
return self._html_output(
- normal_row = u'<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>',
- error_row = u'<li>%s</li>',
+ normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>',
+ error_row = '<li>%s</li>',
row_ender = '</li>',
- help_text_html = u' <span class="helptext">%s</span>',
+ help_text_html = ' <span class="helptext">%s</span>',
errors_on_separate_row = False)
def as_p(self):
"Returns this form rendered as HTML <p>s."
return self._html_output(
- normal_row = u'<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>',
- error_row = u'%s',
+ normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>',
+ error_row = '%s',
row_ender = '</p>',
- help_text_html = u' <span class="helptext">%s</span>',
+ help_text_html = ' <span class="helptext">%s</span>',
errors_on_separate_row = True)
def non_field_errors(self):
@@ -508,7 +508,7 @@ class BoundField(StrAndUnicode):
id_ = widget.attrs.get('id') or self.auto_id
if id_:
attrs = attrs and flatatt(attrs) or ''
- contents = u'<label for="%s"%s>%s</label>' % (widget.id_for_label(id_), attrs, unicode(contents))
+ contents = '<label for="%s"%s>%s</label>' % (widget.id_for_label(id_), attrs, unicode(contents))
return mark_safe(contents)
def css_classes(self, extra_classes=None):