From 6001ba016a3db4701d56abc6d30868d4e5d88dbf Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 9 Aug 2010 21:22:37 +0000 Subject: [soc2010/query-refactor] Merged up to trunk r13556, resolved merge conflicts git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13565 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/forms.py | 8 ++++---- django/forms/formsets.py | 14 ++++++-------- django/forms/widgets.py | 28 ++++++++++++++++++---------- 3 files changed, 28 insertions(+), 22 deletions(-) (limited to 'django/forms') 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'%(label)s%(errors)s%(field)s%(help_text)s', error_row = u'%s', row_ender = u'', - help_text_html = u'
%s', + help_text_html = u'
%s', errors_on_separate_row = False) def as_ul(self): @@ -222,7 +222,7 @@ class BaseForm(StrAndUnicode): normal_row = u'%(errors)s%(label)s %(field)s%(help_text)s', error_row = u'
  • %s
  • ', row_ender = '', - help_text_html = u' %s', + help_text_html = u' %s', errors_on_separate_row = False) def as_p(self): @@ -231,7 +231,7 @@ class BaseForm(StrAndUnicode): normal_row = u'%(label)s %(field)s%(help_text)s

    ', error_row = u'%s', row_ender = '

    ', - help_text_html = u' %s', + help_text_html = u' %s', 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): -- cgit v1.3