diff options
| author | Loic Bistuer <loic.bistuer@sixmedia.com> | 2013-08-28 13:22:47 +0700 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-28 16:39:26 +0300 |
| commit | da800be6ddfdd4c88b48011ef264ea1ec6365725 (patch) | |
| tree | 8fff30e7cdfe09cdaf0bc2cc3ba8b933c3e0e3a6 /django/forms | |
| parent | b89c2a5d9eb70ca36629ef657c98e3371e9a5c4f (diff) | |
Fixed #20986 -- Enabled SelectDateWidget to use custom months
Reviewed by Trac alias MarkusH.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/extras/widgets.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/django/forms/extras/widgets.py b/django/forms/extras/widgets.py index 0b96dc4153..5590a9806a 100644 --- a/django/forms/extras/widgets.py +++ b/django/forms/extras/widgets.py @@ -51,16 +51,23 @@ class SelectDateWidget(Widget): day_field = '%s_day' year_field = '%s_year' - def __init__(self, attrs=None, years=None, required=True): - # years is an optional list/tuple of years to use in the "year" select box. + def __init__(self, attrs=None, years=None, required=True, months=None): self.attrs = attrs or {} self.required = required + + # Optional list or tuple of years to use in the "year" select box. if years: self.years = years else: this_year = datetime.date.today().year self.years = range(this_year, this_year+10) + # Optional dict of months to use in the "month" select box. + if months: + self.months = months + else: + self.months = MONTHS + def render(self, name, value, attrs=None): try: year_val, month_val, day_val = value.year, value.month, value.day @@ -80,7 +87,7 @@ class SelectDateWidget(Widget): 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 = list(six.iteritems(MONTHS)) + choices = list(six.iteritems(self.months)) month_html = self.create_select(name, self.month_field, value, month_val, choices) choices = [(i, i) for i in range(1, 32)] day_html = self.create_select(name, self.day_field, value, day_val, choices) |
