Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Fixed #13390 -- `SplitDateTimeWidget` now recognizes when it'…

…s no longer required. Thanks vaxXxa for bug report and patch.

Backport of r13753 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13754 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 864361aabd02d1ba3b9c12813ec1c45f5f68b49c 1 parent e4bd5e8
@jbronn jbronn authored
Showing with 20 additions and 0 deletions.
  1. +2 −0  django/forms/fields.py
  2. +18 −0 tests/regressiontests/forms/widgets.py
View
2  django/forms/fields.py
@@ -399,6 +399,8 @@ def to_python(self, value):
# components: date and time.
if len(value) != 2:
raise ValidationError(self.error_messages['invalid'])
+ if value[0] in validators.EMPTY_VALUES and value[1] in validators.EMPTY_VALUES:
+ return None
value = '%s %s' % tuple(value)
for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'):
try:
View
18 tests/regressiontests/forms/widgets.py
@@ -1310,3 +1310,21 @@ def test_12048(self):
# w2 ought to be independent of w1, since MultiWidget ought
# to make a copy of its sub-widgets when it is copied.
self.assertEqual(w1.choices, [1,2,3])
+
+ def test_13390(self):
+ # See ticket #13390
+ class SplitDateForm(forms.Form):
+ field = forms.DateTimeField(widget=forms.SplitDateTimeWidget, required=False)
+
+ form = SplitDateForm({'field': ''})
+ self.assertTrue(form.is_valid())
+ form = SplitDateForm({'field': ['', '']})
+ self.assertTrue(form.is_valid())
+
+ class SplitDateRequiredForm(forms.Form):
+ field = forms.DateTimeField(widget=forms.SplitDateTimeWidget, required=True)
+
+ form = SplitDateRequiredForm({'field': ''})
+ self.assertFalse(form.is_valid())
+ form = SplitDateRequiredForm({'field': ['', '']})
+ self.assertFalse(form.is_valid())
Please sign in to comment.
Something went wrong with that request. Please try again.