Opened 16 years ago

Closed 14 years ago

Last modified 12 years ago

#6449 closed Uncategorized (fixed)

datetime filter to access the settings/locales datetime format

Reported by: Harm Geerts Owned by: Marc Garcia
Component: Internationalization Version: dev
Severity: Normal Keywords: i18n-fixed
Cc: Triage Stage: Fixed on a branch
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Currently there is no (known?) way to access the settings/locales datetime format from the templates.
This patch adds a 'datetime' filter to do just that.

Attachments (4)

django-datetime-filter.patch (934 bytes ) - added by Harm Geerts 16 years ago.
django-date-filter.patch (526 bytes ) - added by Harm Geerts 16 years ago.
patch that implements 'x' and 'X' to access the DATE_FORMAT and DATETIME_FORMAT
django-datetime-filter.2.patch (1.5 KB ) - added by Harm Geerts 16 years ago.
Alternativate patch that introduces a new datetime filter which in implements 'x' and 'X' to access DATE_FORMAT and TIME_FORMAT
django-datetime-filter.3.patch (3.2 KB ) - added by Harm Geerts 16 years ago.
patch including documentation, reverted my change to the timefilter because the docs mention date parameters are not allowed

Download all attachments as: .zip

Change History (17)

by Harm Geerts, 16 years ago

comment:1 by Thejaswi Puthraya, 16 years ago

Component: UncategorizedTemplate system
Has patch: set
Keywords: datetime filter added
Triage Stage: UnreviewedAccepted

comment:2 by Malcolm Tredinnick, 16 years ago

Patch needs improvement: set

I don't think we need a whole new filter here. We already have the date and time filters and the date filter can handle datetime objects.

So come up with a new argument for those filters that uses the settings values. I notice that "x" and "X" are free, for example. You'll need two so that you can use both DEFAULT_DATE_FORMAT and DEFAULT_DATETIME_FORMAT with the date filter, I would guess.

by Harm Geerts, 16 years ago

Attachment: django-date-filter.patch added

patch that implements 'x' and 'X' to access the DATE_FORMAT and DATETIME_FORMAT

by Harm Geerts, 16 years ago

Alternativate patch that introduces a new datetime filter which in implements 'x' and 'X' to access DATE_FORMAT and TIME_FORMAT

comment:3 by Harm Geerts, 16 years ago

The datetime filter defaults to DATETIME_FORMAT if no arguments are given

The reason I initially introduced a new filter instead of patching the existing date filter was based on the exact same argument. We already have 2 filters that can handle datetime objects. The only difference is the default if no argument is given (though the time filter supports less output formats).

comment:4 by Thomas Güttler, 16 years ago

Cc: hv@… added
Needs documentation: set

django-datetime-filter.2.patch works for me. But documentation is missing. The filter should be explained in trunk/django/docs/templates.txt.

by Harm Geerts, 16 years ago

patch including documentation, reverted my change to the timefilter because the docs mention date parameters are not allowed

comment:5 by Thomas Güttler, 16 years ago

Why does the template engine not use DATETIME_FORMAT per default (without a filter)?

template:

 {{myinstance.datetimefield}}

should use DATETIME_FORMAT.

Currently I get this:

 2008-07-04 11:09:32.871956

I guess nobody wants this default representation.

comment:6 by Marc Garcia, 16 years ago

Component: Template systemInternationalization
Keywords: i18n-rf added
milestone: post-1.0

comment:7 by Marc Garcia, 16 years ago

I think that this ticket report is invalid. To display a date/datetime in the current locale, just use:

{{ my_date|date:_("DATE_FORMAT") }} or {{ my_date|date:_("DATETIME_FORMAT") }}

Using the settings parameters is meaningless for me, because you just need to define the locale of your application, and then use the format in that locale.

Of course other tickets could be opened for:

  • Use current locale as default when displaying dates.
  • Add more formats like DATE_FORMAT for short dates "mm/dd/yyyy", or for including wee day, because DATE_FORMAT will display a long date without week date.

Please, close the ticket as invalid unless I'm missing something.

comment:8 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:9 by Marc Garcia, 15 years ago

Keywords: i18n-fixed added; datetime filter i18n-rf removed
Owner: changed from nobody to Marc Garcia

Fixed in branches/soc2009/i18n-improvements.

comment:10 by Marc Garcia, 15 years ago

Triage Stage: AcceptedFixed on a branch

comment:11 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

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

in reply to:  7 comment:12 by bjourne, 14 years ago

Replying to garcia_marc:

I think that this ticket report is invalid. To display a date/datetime in the current locale, just use:

{{ my_date|date:_("DATE_FORMAT") }} or {{ my_date|date:_("DATETIME_FORMAT") }}

Maybe this trick could be added to the documentation? It solves the problem very elegantly, but the solution is not very obvious (not to me anyway).

comment:13 by Thomas Güttler, 12 years ago

Cc: hv@… removed
Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset
Note: See TracTickets for help on using tickets.
Back to Top