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) diff --git a/tests/regressiontests/forms/extra.py b/tests/regressiontests/forms/extra.py index eb586d0ecc..2d25530a48 100644 --- a/tests/regressiontests/forms/extra.py +++ b/tests/regressiontests/forms/extra.py @@ -364,6 +364,82 @@ True 2008-04-01 +USE_L10N tests + +>>> from django.utils import translation +>>> translation.activate('nl') +>>> from django.conf import settings +>>> settings.USE_L10N=True + +>>> w.value_from_datadict({'date_year': '2010', 'date_month': '8', 'date_day': '13'}, {}, 'date') +'13-08-2010' + +>>> print w.render('date', '13-08-2010') + + + + +>>> translation.deactivate() + # MultiWidget and MultiValueField ############################################# # MultiWidgets are widgets composed of other widgets. They are usually # combined with MultiValueFields - a field that is composed of other fields.