summaryrefslogtreecommitdiff
path: root/django/forms/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/forms/forms.py')
-rw-r--r--django/forms/forms.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index b3718efa9a..7b2bc66fc7 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -18,10 +18,10 @@ __all__ = ('BaseForm', 'Form')
NON_FIELD_ERRORS = '__all__'
def pretty_name(name):
- """Converts 'first_name' to 'First name'"""
- if not name:
- return u''
- return name.replace('_', ' ').capitalize()
+ """Converts 'first_name' to 'First name'"""
+ if not name:
+ return u''
+ return name.replace('_', ' ').capitalize()
def get_declared_fields(bases, attrs, with_base_fields=True):
"""
@@ -35,7 +35,7 @@ def get_declared_fields(bases, attrs, with_base_fields=True):
Also integrates any additional media definitions
"""
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
- fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
+ fields.sort(key=lambda x: x[1].creation_counter)
# If this class is subclassing another Form, add that Form's fields.
# Note that we loop over the bases in *reverse*. This is necessary in
@@ -213,7 +213,7 @@ class BaseForm(StrAndUnicode):
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 />%s',
+ help_text_html = u'<br /><span class="helptext">%s</span>',
errors_on_separate_row = False)
def as_ul(self):
@@ -222,7 +222,7 @@ class BaseForm(StrAndUnicode):
normal_row = u'<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>',
error_row = u'<li>%s</li>',
row_ender = '</li>',
- help_text_html = u' %s',
+ help_text_html = u' <span class="helptext">%s</span>',
errors_on_separate_row = False)
def as_p(self):
@@ -231,7 +231,7 @@ class BaseForm(StrAndUnicode):
normal_row = u'<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>',
error_row = u'%s',
row_ender = '</p>',
- help_text_html = u' %s',
+ help_text_html = u' <span class="helptext">%s</span>',
errors_on_separate_row = True)
def non_field_errors(self):
@@ -423,6 +423,7 @@ class BoundField(StrAndUnicode):
"""
if not widget:
widget = self.field.widget
+
attrs = attrs or {}
auto_id = self.auto_id
if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
@@ -430,6 +431,7 @@ class BoundField(StrAndUnicode):
attrs['id'] = auto_id
else:
attrs['id'] = self.html_initial_id
+
if not self.form.is_bound:
data = self.form.initial.get(self.name, self.field.initial)
if callable(data):
@@ -439,6 +441,8 @@ class BoundField(StrAndUnicode):
data = self.form.initial.get(self.name, self.field.initial)
else:
data = self.data
+ data = self.field.prepare_value(data)
+
if not only_initial:
name = self.html_name
else: