Ticket #5917: SelectDateWidget_with_test.3.diff

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

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

  • 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
    3738        except (AttributeError, TypeError, ValueError):
    3839            year_val = month_val = day_val = None
  • 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