Code

Opened 6 years ago

Closed 4 years ago

Last modified 2 years ago

#6449 closed Uncategorized (fixed)

datetime filter to access the settings/locales datetime format

Reported by: Harm Geerts Owned by: garcia_marc
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 6 years ago.
django-date-filter.patch (526 bytes) - added by Harm Geerts 6 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 6 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 6 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 6 years ago by Harm Geerts

comment:1 Changed 6 years ago by thejaswi_puthraya

  • Component changed from Uncategorized to Template system
  • Has patch set
  • Keywords datetime filter added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by mtredinnick

  • 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 6 years ago by Harm Geerts

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

Changed 6 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 6 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 6 years ago by guettli

  • 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 6 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 6 years ago by guettli

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 6 years ago by garcia_marc

  • Component changed from Template system to Internationalization
  • Keywords i18n-rf added
  • milestone set to post-1.0

comment:7 follow-up: Changed 6 years ago by 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") }}

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 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:9 Changed 5 years ago by garcia_marc

  • Keywords i18n-fixed added; datetime filter i18n-rf removed
  • Owner changed from nobody to garcia_marc

Fixed in branches/soc2009/i18n-improvements.

comment:10 Changed 5 years ago by garcia_marc

  • Triage Stage changed from Accepted to Fixed on a branch

comment:11 Changed 4 years ago by jezdez

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

comment:12 in reply to: ↑ 7 Changed 4 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 2 years ago by guettli

  • Cc hv@… removed
  • Easy pickings unset
  • Severity set to Normal
  • Type set to Uncategorized
  • UI/UX unset

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.