Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Justin Bronn authored
2  django/forms/fields.py
@@ -399,6 +399,8 @@ def to_python(self, value):
399 399
             # components: date and time.
400 400
             if len(value) != 2:
401 401
                 raise ValidationError(self.error_messages['invalid'])
  402
+            if value[0] in validators.EMPTY_VALUES and value[1] in validators.EMPTY_VALUES:
  403
+                return None
402 404
             value = '%s %s' % tuple(value)
403 405
         for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'):
404 406
             try:
18  tests/regressiontests/forms/widgets.py
@@ -1310,3 +1310,21 @@ def test_12048(self):
1310 1310
         # w2 ought to be independent of w1, since MultiWidget ought
1311 1311
         # to make a copy of its sub-widgets when it is copied.
1312 1312
         self.assertEqual(w1.choices, [1,2,3])
  1313
+
  1314
+    def test_13390(self):
  1315
+        # See ticket #13390
  1316
+        class SplitDateForm(forms.Form):
  1317
+            field = forms.DateTimeField(widget=forms.SplitDateTimeWidget, required=False)
  1318
+
  1319
+        form = SplitDateForm({'field': ''})
  1320
+        self.assertTrue(form.is_valid())
  1321
+        form = SplitDateForm({'field': ['', '']})
  1322
+        self.assertTrue(form.is_valid())
  1323
+
  1324
+        class SplitDateRequiredForm(forms.Form):
  1325
+            field = forms.DateTimeField(widget=forms.SplitDateTimeWidget, required=True)
  1326
+
  1327
+        form = SplitDateRequiredForm({'field': ''})
  1328
+        self.assertFalse(form.is_valid())
  1329
+        form = SplitDateRequiredForm({'field': ['', '']})
  1330
+        self.assertFalse(form.is_valid())

0 notes on commit 864361a

Please sign in to comment.
Something went wrong with that request. Please try again.