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)

ticket_6231.patch (15.1 KB) - added by David JL 15 years ago.
patch for ticket #6231
ticket_6231_v2.patch (15.1 KB) - added by Bernd Schlapsi 15 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 15 years ago.
integrated patch for ticket #9124
ticket_6231_v4.patch (25.1 KB) - added by Bernd Schlapsi 14 years ago.
New patch-version that works with current django-version (after Changeset [10585])

Download all attachments as: .zip

Change History (21)

comment:1 Changed 15 years ago by Gary Wilson

Triage Stage: UnreviewedAccepted

comment:2 Changed 15 years ago by Martin Conte Mac Donell <Reflejo@…>

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

comment:3 Changed 15 years ago by Bernd Schlapsi

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 Martin Conte Mac Donell <Reflejo@…>

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 Bernd Schlapsi

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?

Changed 15 years ago by David JL

Attachment: ticket_6231.patch added

patch for ticket #6231

comment:6 Changed 15 years ago by David JL

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

David.

comment:7 Changed 15 years ago by David JL

Has patch: set

comment:8 Changed 15 years ago by Marc Garcia

Keywords: i18n-rf added

comment:9 Changed 15 years ago by Marc Garcia

Component: django.newformsInternationalization
milestone: post-1.0

Changed 15 years ago by Bernd Schlapsi

Attachment: ticket_6231_v2.patch added

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

Changed 15 years ago by Bernd Schlapsi

Attachment: ticket_6231_v3.patch added

integrated patch for ticket #9124

comment:10 Changed 14 years ago by anonymous

Cc: andy@… added

comment:11 Changed 14 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:12 Changed 14 years ago by Jacob

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

Changed 14 years ago by Bernd Schlapsi

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 Marc Garcia

Owner: changed from nobody to Marc Garcia

comment:14 Changed 14 years ago by Marc Garcia

Resolution: fixed
Status: newclosed

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

comment:15 Changed 14 years ago by Marc Garcia

Resolution: fixed
Status: closedreopened

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

comment:16 Changed 14 years ago by Marc Garcia

Triage Stage: AcceptedFixed on a branch

comment:17 Changed 13 years ago by Jannis Leidel

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