#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)
Change History (17)
Changed 16 years ago by
Attachment: | django-datetime-filter.patch added |
---|
comment:1 Changed 16 years ago by
Component: | Uncategorized → Template system |
---|---|
Has patch: | set |
Keywords: | datetime filter added |
Triage Stage: | Unreviewed → Accepted |
comment:2 Changed 16 years ago by
Patch needs improvement: | set |
---|
Changed 16 years ago by
Attachment: | django-date-filter.patch added |
---|
patch that implements 'x' and 'X' to access the DATE_FORMAT and DATETIME_FORMAT
Changed 16 years ago by
Attachment: | django-datetime-filter.2.patch added |
---|
Alternativate patch that introduces a new datetime filter which in implements 'x' and 'X' to access DATE_FORMAT and TIME_FORMAT
comment:3 Changed 16 years ago by
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 15 years ago by
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 15 years ago by
Attachment: | django-datetime-filter.3.patch added |
---|
patch including documentation, reverted my change to the timefilter because the docs mention date parameters are not allowed
comment:5 Changed 15 years ago by
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 15 years ago by
Component: | Template system → Internationalization |
---|---|
Keywords: | i18n-rf added |
milestone: | → post-1.0 |
comment:7 follow-up: 12 Changed 15 years ago by
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:9 Changed 14 years ago by
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 14 years ago by
Triage Stage: | Accepted → Fixed on a branch |
---|
comment:11 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → 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 Changed 14 years ago by
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 12 years ago by
Cc: | hv@… removed |
---|---|
Easy pickings: | unset |
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
I don't think we need a whole new filter here. We already have the
date
andtime
filters and thedate
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
andDEFAULT_DATETIME_FORMAT
with thedate
filter, I would guess.