Opened 9 years ago

Closed 7 years ago

Last modified 5 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: master
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 9 years ago.
django-date-filter.patch (526 bytes) - added by Harm Geerts 9 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 9 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 9 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)

Changed 9 years ago by Harm Geerts

comment:1 Changed 9 years ago by Thejaswi Puthraya

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

comment:2 Changed 9 years ago by Malcolm Tredinnick

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.

Changed 9 years ago by Harm Geerts

Attachment: django-date-filter.patch added

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

Changed 9 years ago by Harm Geerts

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

comment:3 Changed 9 years ago by Harm Geerts

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 Changed 9 years ago by Thomas Güttler

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.

Changed 9 years ago by Harm Geerts

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

comment:5 Changed 8 years ago by Thomas Güttler

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 Changed 8 years ago by Marc Garcia

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

comment:7 Changed 8 years ago by Marc Garcia

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 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:9 Changed 7 years ago by Marc Garcia

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

Fixed in branches/soc2009/i18n-improvements.

comment:10 Changed 7 years ago by Marc Garcia

Triage Stage: AcceptedFixed on a branch

comment:11 Changed 7 years ago by Jannis Leidel

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.

comment:12 in reply to:  7 Changed 7 years ago by bjourne

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 Changed 5 years ago by Thomas Güttler

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