Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #17542 -- Gracefully handle errors when checking if the values …

…of a SelectDateWidget has changed if it's not required. Thanks, pigletto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17436 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 56d787df99a923cf96d02f9cd07ca8d383dbc028 1 parent e734477
Jannis Leidel jezdez authored
9 django/forms/extras/widgets.py
View
@@ -136,6 +136,9 @@ def create_select(self, name, field, value, val, choices):
return select_html
def _has_changed(self, initial, data):
- input_format = get_format('DATE_INPUT_FORMATS')[0]
- data = datetime_safe.datetime.strptime(data, input_format).date()
- return super(SelectDateWidget, self)._has_changed(initial, data)
+ try:
+ input_format = get_format('DATE_INPUT_FORMATS')[0]
+ data = datetime_safe.datetime.strptime(data, input_format).date()
+ except (TypeError, ValueError):
+ pass
+ return super(SelectDateWidget, self)._has_changed(initial, data)
12 tests/regressiontests/forms/tests/extra.py
View
@@ -18,6 +18,9 @@
class GetDate(Form):
mydate = DateField(widget=SelectDateWidget)
+class GetNotRequiredDate(Form):
+ mydate = DateField(widget=SelectDateWidget, required=False)
+
class GetDateShowHiddenInitial(Form):
mydate = DateField(widget=SelectDateWidget, show_hidden_initial=True)
@@ -619,6 +622,15 @@ class FormWithImage(Form):
self.assertTrue(FormWithFile().is_multipart())
self.assertTrue(FormWithImage().is_multipart())
+ def test_field_not_required(self):
+ b = GetNotRequiredDate({
+ 'mydate_year': '',
+ 'mydate_month': '',
+ 'mydate_day': ''
+ })
+ self.assertFalse(b.has_changed())
+
+
class FormsExtraL10NTestCase(TestCase):
def setUp(self):
Please sign in to comment.
Something went wrong with that request. Please try again.