1
0
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:
Russell Keith-Magee
2010-04-28 15:39:26 +00:00
parent 9d8492c169
commit 5926a26e92
2 changed files with 88 additions and 5 deletions

View File

@@ -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)