Opened 17 years ago

Closed 15 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)

ticket_6231.patch (15.1 KB ) - added by David JL 17 years ago.
patch for ticket #6231
ticket_6231_v2.patch (15.1 KB ) - added by Bernd Schlapsi 16 years ago.
New patch-version that works with current django-version (replaced newforms with forms)
ticket_6231_v3.patch (26.0 KB ) - added by Bernd Schlapsi 16 years ago.
integrated patch for ticket #9124
ticket_6231_v4.patch (25.1 KB ) - added by Bernd Schlapsi 16 years ago.
New patch-version that works with current django-version (after Changeset [10585])

Download all attachments as: .zip

Change History (21)

comment:1 by Gary Wilson, 17 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Martin Conte Mac Donell <Reflejo@…>, 17 years ago

Actually SelectDateWidget isn't returning MONTH/DAY/YEAR format.

comment:3 by Bernd Schlapsi, 17 years ago

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 by Martin Conte Mac Donell <Reflejo@…>, 17 years ago

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 by Bernd Schlapsi, 17 years ago

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?

by David JL, 17 years ago

Attachment: ticket_6231.patch added

patch for ticket #6231

comment:6 by David JL, 17 years ago

The patch above addresses this issue and also add a TimeSelectWidget.
It include regression tests.

David.

comment:7 by David JL, 17 years ago

Has patch: set

comment:8 by Marc Garcia, 16 years ago

Keywords: i18n-rf added

comment:9 by Marc Garcia, 16 years ago

Component: django.newformsInternationalization
milestone: post-1.0

by Bernd Schlapsi, 16 years ago

Attachment: ticket_6231_v2.patch added

New patch-version that works with current django-version (replaced newforms with forms)

by Bernd Schlapsi, 16 years ago

Attachment: ticket_6231_v3.patch added

integrated patch for ticket #9124

comment:10 by anonymous, 16 years ago

Cc: andy@… added

comment:11 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:12 by Jacob, 16 years ago

Please don't integrate patches like this; it makes things *really* hard to figure out. One patch per ticket.

by Bernd Schlapsi, 16 years ago

Attachment: ticket_6231_v4.patch added

New patch-version that works with current django-version (after Changeset [10585])

comment:13 by Marc Garcia, 15 years ago

Owner: changed from nobody to Marc Garcia

comment:14 by Marc Garcia, 15 years ago

Resolution: fixed
Status: newclosed

(In [11412]) [soc2009/i18n] Fixed #6231. SelectDateWidget uses localized DATE_FORMAT setting.

comment:15 by Marc Garcia, 15 years ago

Resolution: fixed
Status: closedreopened

Last commit shouldn't close the ticket, but Ref it. Reopening.

comment:16 by Marc Garcia, 15 years ago

Triage Stage: AcceptedFixed on a branch

comment:17 by Jannis Leidel, 15 years ago

Resolution: fixed
Status: reopenedclosed

(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.

Note: See TracTickets for help on using tickets.
Back to Top