Opened 15 years ago
Closed 13 years ago
#6231 closed (fixed)
SelectDateWidget: field order as a result of DATE_FORMAT
Reported by: | Bernd Schlapsi | Owned by: | Marc Garcia |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Keywords: | i18n-rf | |
Cc: | andy@… | Triage Stage: | Fixed on a branch |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The SelectDateWidget had a fix output in the format: MONTH/DAY/YEAR.
It would be nice, if the format could follow the DATE_FORMAT in settings.py and take care of the correct order.
Attachments (4)
Change History (21)
comment:1 Changed 15 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 Changed 15 years ago by
comment:3 Changed 15 years ago by
This is the source-code for the render function of SelectDateWidget from trunk/django/newforms/extras/widgets.py
def render(self, name, value, attrs=None): try: value = datetime.date(*map(int, value.split('-'))) year_val, month_val, day_val = value.year, value.month, value.day except (AttributeError, TypeError, ValueError): year_val = month_val = day_val = None output = [] month_choices = MONTHS.items() month_choices.sort() select_html = Select(choices=month_choices).render(self.month_field % name, month_val) output.append(select_html) day_choices = [(i, i) for i in range(1, 32)] select_html = Select(choices=day_choices).render(self.day_field % name, day_val) output.append(select_html) year_choices = [(i, i) for i in self.years] select_html = Select(choices=year_choices).render(self.year_field % name, year_val) output.append(select_html) return mark_safe(u'\n'.join(output))
If I read/understand this function correct, the SelectDateWidget returns MONTH/DAY/YEAR format
comment:4 Changed 15 years ago by
I see, you mean the order not the literally "slash".
DATE_FORMAT Can take many variables that do not apply in select boxes. Consider this case: "%A, %B %Y". How do you render this?
comment:5 Changed 15 years ago by
I know that DATE_FORMAT can take a lot of variables. I don't know a good solution yet. I am new to python and django, otherwise I would have tried to write a patch. But I think it's important to give this widget a bit of flexibility. In Europe we don't use the date format MONTH/DAY/YEAR.
Could it be a (good) solution to check the usual date formats? If none of them would be submitted, the widget could use a default date format. What do you think?
comment:6 Changed 15 years ago by
The patch above addresses this issue and also add a TimeSelectWidget.
It include regression tests.
David.
comment:7 Changed 15 years ago by
Has patch: | set |
---|
comment:8 Changed 15 years ago by
Keywords: | i18n-rf added |
---|
comment:9 Changed 15 years ago by
Component: | django.newforms → Internationalization |
---|---|
milestone: | → post-1.0 |
Changed 15 years ago by
Attachment: | ticket_6231_v2.patch added |
---|
New patch-version that works with current django-version (replaced newforms with forms)
comment:10 Changed 14 years ago by
Cc: | andy@… added |
---|
comment:12 Changed 14 years ago by
Please don't integrate patches like this; it makes things *really* hard to figure out. One patch per ticket.
Changed 14 years ago by
Attachment: | ticket_6231_v4.patch added |
---|
New patch-version that works with current django-version (after Changeset [10585])
comment:13 Changed 14 years ago by
Owner: | changed from nobody to Marc Garcia |
---|
comment:14 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:15 Changed 14 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Last commit shouldn't close the ticket, but Ref it. Reopening.
comment:16 Changed 14 years ago by
Triage Stage: | Accepted → Fixed on a branch |
---|
comment:17 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [11964]) Fixed #7980 - Improved i18n framework to support locale aware formatting (dates and numbers) and form processing.
Thanks to Marc Garcia for working on this during his Google Summer of Code 2009!
Additionally fixes #1061, #2203, #3940, #5526, #6449, #6231, #6693, #6783, #9366 and #10891.
Actually SelectDateWidget isn't returning MONTH/DAY/YEAR format.