Ticket #13390: 13390.patch

File 13390.patch, 1.7 KB (added by phxx, 5 years ago)

Fix and tests in one patch.

  • django/forms/fields.py

    === modified file 'django/forms/fields.py'
     
    397397            # components: date and time.
    398398            if len(value) != 2:
    399399                raise ValidationError(self.error_messages['invalid'])
     400            if value[0] in validators.EMPTY_VALUES and value[1] in validators.EMPTY_VALUES:
     401                return None
    400402            value = '%s %s' % tuple(value)
    401403        for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'):
    402404            try:
  • tests/regressiontests/forms/widgets.py

    === modified file 'tests/regressiontests/forms/widgets.py'
     
    13091309        # w2 ought to be independent of w1, since MultiWidget ought
    13101310        # to make a copy of its sub-widgets when it is copied.
    13111311        self.assertEqual(w1.choices, [1,2,3])
     1312
     1313    def test_13390(self):
     1314        # See ticket #13390
     1315        class SplitDateForm(forms.Form):
     1316            field = forms.DateTimeField(widget=forms.SplitDateTimeWidget, required=False)
     1317
     1318        form = SplitDateForm({'field': ''})
     1319        self.assertTrue(form.is_valid())
     1320        form = SplitDateForm({'field': ['', '']})
     1321        self.assertTrue(form.is_valid())
     1322
     1323        class SplitDateRequiredForm(forms.Form):
     1324            field = forms.DateTimeField(widget=forms.SplitDateTimeWidget, required=True)
     1325
     1326        form = SplitDateRequiredForm({'field': ''})
     1327        self.assertFalse(form.is_valid())
     1328        form = SplitDateRequiredForm({'field': ['', '']})
     1329        self.assertFalse(form.is_valid())
Back to Top