Opened 8 years ago

Closed 6 years ago

#6231 closed (fixed)

SelectDateWidget: field order as a result of DATE_FORMAT

Reported by: Bernd Schlapsi Owned by: garcia_marc
Component: Internationalization Version: master
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: UI/UX:

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 izi 7 years ago.
patch for ticket #6231
ticket_6231_v2.patch (15.1 KB) - added by Bernd Schlapsi 7 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 7 years ago.
integrated patch for ticket #9124
ticket_6231_v4.patch (25.1 KB) - added by Bernd Schlapsi 6 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 8 years ago by gwilson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

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

comment:3 Changed 8 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 8 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 8 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 7 years ago by izi

patch for ticket #6231

comment:6 Changed 7 years ago by izi

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

David.

comment:7 Changed 7 years ago by izi

  • Has patch set

comment:8 Changed 7 years ago by garcia_marc

  • Keywords i18n-rf added

comment:9 Changed 7 years ago by garcia_marc

  • Component changed from django.newforms to Internationalization
  • milestone set to post-1.0

Changed 7 years ago by Bernd Schlapsi

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

Changed 7 years ago by Bernd Schlapsi

integrated patch for ticket #9124

comment:10 Changed 7 years ago by anonymous

  • Cc andy@… added

comment:11 Changed 6 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:12 Changed 6 years ago by jacob

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

Changed 6 years ago by Bernd Schlapsi

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

comment:13 Changed 6 years ago by garcia_marc

  • Owner changed from nobody to garcia_marc

comment:14 Changed 6 years ago by garcia_marc

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:15 Changed 6 years ago by garcia_marc

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:16 Changed 6 years ago by garcia_marc

  • Triage Stage changed from Accepted to Fixed on a branch

comment:17 Changed 6 years ago by jezdez

  • Resolution set to fixed
  • Status changed from reopened to 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.

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