Ticket #5917: SelectDateWidget_with_test.2.diff

File SelectDateWidget_with_test.2.diff, 1.2 KB (added by Joseph Long, 17 years ago)

Checks isinstance of string in render, and adds a test. Removes TypeError from exceptions, since isinstance means that can't be raised (as pointed out by SmileyChris)

  • django/newforms/extras/widgets.py

     
    3232
    3333    def render(self, name, value, attrs=None):
    3434        try:
    35             value = datetime.date(*map(int, value.split('-')))
     35            if isinstance(value, basestring):
     36                value = datetime.date(*map(int, value.split('-')))
    3637            year_val, month_val, day_val = value.year, value.month, value.day
    37         except (AttributeError, TypeError, ValueError):
     38        except (AttributeError, ValueError):
    3839            year_val = month_val = day_val = None
    3940
    4041        output = []
  • tests/regressiontests/forms/extra.py

     
    143143<option value="2015">2015</option>
    144144<option value="2016">2016</option>
    145145</select>
     146>>> w.render('mydate', datetime.date(2010, 4, 15)) == w.render('mydate', '2010-04-15')
     147True
    146148
    147149Using a SelectDateWidget in a form:
    148150
Back to Top