summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-04-28 15:39:26 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-04-28 15:39:26 +0000
commit5926a26e920c0543641ea1b06ee78c61c80e947d (patch)
tree805433f5a5a1e78020f4738b93876e06af0caca8 /django
parent9d8492c169d54b727ab387132456d4c1526cff06 (diff)
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
Diffstat (limited to 'django')
-rw-r--r--django/forms/extras/widgets.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/django/forms/extras/widgets.py b/django/forms/extras/widgets.py
index 173ef2e1de..108b2c56e2 100644
--- a/django/forms/extras/widgets.py
+++ b/django/forms/extras/widgets.py
@@ -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)