Code

Ticket #5917: SelectDateWidget_with_test.3.diff

File SelectDateWidget_with_test.3.diff, 1.1 KB (added by josePhoenix, 6 years ago)

Nevermind removing TypeError. It could still be raised.. this is the better version of the patch

Line 
1Index: django/newforms/extras/widgets.py
2===================================================================
3--- django/newforms/extras/widgets.py   (revision 7027)
4+++ django/newforms/extras/widgets.py   (working copy)
5@@ -32,7 +32,8 @@
6 
7     def render(self, name, value, attrs=None):
8         try:
9-            value = datetime.date(*map(int, value.split('-')))
10+            if isinstance(value, basestring):
11+                value = datetime.date(*map(int, value.split('-')))
12             year_val, month_val, day_val = value.year, value.month, value.day
13         except (AttributeError, TypeError, ValueError):
14             year_val = month_val = day_val = None
15Index: tests/regressiontests/forms/extra.py
16===================================================================
17--- tests/regressiontests/forms/extra.py        (revision 6865)
18+++ tests/regressiontests/forms/extra.py        (working copy)
19@@ -143,6 +143,8 @@
20 <option value="2015">2015</option>
21 <option value="2016">2016</option>
22 </select>
23+>>> w.render('mydate', datetime.date(2010, 4, 15)) == w.render('mydate', '2010-04-15')
24+True
25 
26 Using a SelectDateWidget in a form:
27