Permalink
Browse files

Fixed #13621 -- Corrected the handling of input formats on date/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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13484 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 25f0ff4 commit 75d018f63164a9e307c0e7604af903fbbe23c21f @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
View
@@ -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.

0 comments on commit 75d018f

Please sign in to comment.