Ticket #17542: patch_for_17542.diff

File patch_for_17542.diff, 1.8 KB (added by Maciej Wiśniowski, 13 years ago)
  • django/forms/extras/widgets.py

    diff --git a/django/forms/extras/widgets.py b/django/forms/extras/widgets.py
    index 4fb4869..a66b759 100644
    a b class SelectDateWidget(Widget):  
    136136        return select_html
    137137
    138138    def _has_changed(self, initial, data):
    139         input_format = get_format('DATE_INPUT_FORMATS')[0]
    140         data = datetime_safe.datetime.strptime(data, input_format).date()
     139        try:
     140            input_format = get_format('DATE_INPUT_FORMATS')[0]
     141            data = datetime_safe.datetime.strptime(data, input_format).date()
     142        except (TypeError, ValueError):
     143            pass
    141144        return super(SelectDateWidget, self)._has_changed(initial, data)
     145 No newline at end of file
  • tests/regressiontests/forms/tests/extra.py

    diff --git a/tests/regressiontests/forms/tests/extra.py b/tests/regressiontests/forms/tests/extra.py
    index 3c5dfab..c873af7 100644
    a b from .error_messages import AssertFormErrorsMixin  
    1818class GetDate(Form):
    1919    mydate = DateField(widget=SelectDateWidget)
    2020
     21class GetNotRequiredDate(Form):
     22    mydate = DateField(widget=SelectDateWidget, required=False)
     23
    2124class GetDateShowHiddenInitial(Form):
    2225    mydate = DateField(widget=SelectDateWidget, show_hidden_initial=True)
    2326
    class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):  
    619622        self.assertTrue(FormWithFile().is_multipart())
    620623        self.assertTrue(FormWithImage().is_multipart())
    621624
     625    def test_field_not_required(self):
     626        b = GetNotRequiredDate({
     627            'mydate_year': '',
     628            'mydate_month': '',
     629            'mydate_day': ''
     630        })
     631        self.assertFalse(b.has_changed())
     632
     633
    622634
    623635class FormsExtraL10NTestCase(TestCase):
    624636    def setUp(self):
Back to Top