Permalink
Browse files

[1.2.X] Fixed #13621 -- Corrected the handling of input formats on da…

…te/time form fields. Thanks to bufke for the report, zerok and jacmkno for their work on the patch, and Karen, Jannis and Alex for feedback.

Backport of r13484 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13486 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent aa59bc7 commit 908b91b69ebdc5947bdb8944b143835e1d7d2126 @freakboy3742 freakboy3742 committed Aug 5, 2010
Showing with 913 additions and 9 deletions.
  1. +17 −9 django/forms/widgets.py
  2. +894 −0 tests/regressiontests/forms/input_formats.py
  3. +2 −0 tests/regressiontests/forms/tests.py
@@ -308,9 +308,13 @@ def __init__(self, attrs=None, format=None):
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 @@ def __init__(self, attrs=None, format=None):
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 @@ def __init__(self, attrs=None, format=None):
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):
Oops, something went wrong. Retry.

0 comments on commit 908b91b

Please sign in to comment.