mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #12986 -- Ensured that SelectDateField repopulates correctly when USE_L10N=True and locale has a default date input format other than %Y-%m-%d. Thanks to wim@go2people.nl for the report, and walteralini for his draft patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13041 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -43,10 +43,17 @@ class SelectDateWidget(Widget):
|
||||
except AttributeError:
|
||||
year_val = month_val = day_val = None
|
||||
if isinstance(value, basestring):
|
||||
match = RE_DATE.match(value)
|
||||
if match:
|
||||
year_val, month_val, day_val = [int(v) for v in match.groups()]
|
||||
|
||||
if settings.USE_L10N:
|
||||
try:
|
||||
input_format = get_format('DATE_INPUT_FORMATS')[0]
|
||||
v = datetime.datetime.strptime(value, input_format)
|
||||
year_val, month_val, day_val = v.year, v.month, v.day
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
match = RE_DATE.match(value)
|
||||
if match:
|
||||
year_val, month_val, day_val = [int(v) for v in match.groups()]
|
||||
choices = [(i, i) for i in self.years]
|
||||
year_html = self.create_select(name, self.year_field, value, year_val, choices)
|
||||
choices = MONTHS.items()
|
||||
@@ -98,7 +105,7 @@ class SelectDateWidget(Widget):
|
||||
id_ = self.attrs['id']
|
||||
else:
|
||||
id_ = 'id_%s' % name
|
||||
if not (self.required and value):
|
||||
if not (self.required and val):
|
||||
choices.insert(0, self.none_value)
|
||||
local_attrs = self.build_attrs(id=field % id_)
|
||||
s = Select(choices=choices)
|
||||
|
||||
Reference in New Issue
Block a user