﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5917	django.newforms.extras.widgets.SelectDateWidget	Camille Harang	Chris Beaven	"Hi,

django.newforms.extras.widgets.SelectDateWidget is not correctly passing the previous selected value to the HTML renderer because it sometimes receives the value as a datetime.date field or a unicode string. The code only handles it as unicode, it splits it and converts it to datetime.date, so when it receives it directly as a datetime.date try/except resets the default value as None :


{{{
    def render(self, name, value, attrs=None):
        try:
            value = datetime.date(*map(int, value.split('-')))
            year_val, month_val, day_val = value.year, value.month, value.day
        except (AttributeError, TypeError, ValueError):
            year_val = month_val = day_val = None
}}}


I added a type value test and now it works:


{{{
    def render(self, name, value, attrs=None):
        try:
            if type(value) == type(u''):
                value = datetime.date(*map(int, value.split('-')))
            year_val, month_val, day_val = value.year, value.month, value.day
        except (AttributeError, TypeError, ValueError):
            year_val = month_val = day_val = None

}}}

Regards.

Camille.
"		closed	Forms	dev		fixed	newforms widgets SelectDateWidget		Ready for checkin	1	0	0	0	0	0
