summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/forms.py8
-rw-r--r--django/forms/formsets.py14
-rw-r--r--django/forms/widgets.py28
3 files changed, 28 insertions, 22 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index b3718efa9a..dc0800b436 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -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):
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 3804f2b3c1..508950eee9 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -199,14 +199,12 @@ class BaseFormSet(StrAndUnicode):
# A sort function to order things numerically ascending, but
# None should be sorted below anything else. Allowing None as
# a comparison value makes it so we can leave ordering fields
- # blamk.
- def compare_ordering_values(x, y):
- if x[1] is None:
- return 1
- if y[1] is None:
- return -1
- return x[1] - y[1]
- self._ordering.sort(compare_ordering_values)
+ # blank.
+ def compare_ordering_key(k):
+ if k[1] is None:
+ return (1, 0) # +infinity, larger than any number
+ return (0, k[1])
+ self._ordering.sort(key=compare_ordering_key)
# Return a list of form.cleaned_data dicts in the order spcified by
# the form data.
return [self.forms[i[0]] for i in self._ordering]
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index e3799c69ad..7a812ecc84 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -229,7 +229,7 @@ class TextInput(Input):
class PasswordInput(Input):
input_type = 'password'
- def __init__(self, attrs=None, render_value=True):
+ def __init__(self, attrs=None, render_value=False):
super(PasswordInput, self).__init__(attrs)
self.render_value = render_value
@@ -308,9 +308,13 @@ class DateInput(Input):
super(DateInput, self).__init__(attrs)
if format:
self.format = format
+ self.manual_format = True
+ else:
+ self.format = formats.get_format('DATE_INPUT_FORMATS')[0]
+ self.manual_format = False
def _format_value(self, value):
- if self.is_localized:
+ if self.is_localized and not self.manual_format:
return formats.localize_input(value)
elif hasattr(value, 'strftime'):
value = datetime_safe.new_date(value)
@@ -336,9 +340,13 @@ class DateTimeInput(Input):
super(DateTimeInput, self).__init__(attrs)
if format:
self.format = format
+ self.manual_format = True
+ else:
+ self.format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
+ self.manual_format = False
def _format_value(self, value):
- if self.is_localized:
+ if self.is_localized and not self.manual_format:
return formats.localize_input(value)
elif hasattr(value, 'strftime'):
value = datetime_safe.new_datetime(value)
@@ -364,9 +372,13 @@ class TimeInput(Input):
super(TimeInput, self).__init__(attrs)
if format:
self.format = format
+ self.manual_format = True
+ else:
+ self.format = formats.get_format('TIME_INPUT_FORMATS')[0]
+ self.manual_format = False
def _format_value(self, value):
- if self.is_localized:
+ if self.is_localized and not self.manual_format:
return formats.localize_input(value)
elif hasattr(value, 'strftime'):
return value.strftime(self.format)
@@ -751,12 +763,8 @@ class SplitDateTimeWidget(MultiWidget):
time_format = TimeInput.format
def __init__(self, attrs=None, date_format=None, time_format=None):
- if date_format:
- self.date_format = date_format
- if time_format:
- self.time_format = time_format
- widgets = (DateInput(attrs=attrs, format=self.date_format),
- TimeInput(attrs=attrs, format=self.time_format))
+ widgets = (DateInput(attrs=attrs, format=date_format),
+ TimeInput(attrs=attrs, format=time_format))
super(SplitDateTimeWidget, self).__init__(widgets, attrs)
def decompress(self, value):