#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)
by , 18 years ago
| Attachment: | django-datetime-filter.patch added |
|---|
comment:1 by , 18 years ago
| Component: | Uncategorized → Template system |
|---|---|
| Has patch: | set |
| Keywords: | datetime filter added |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 18 years ago
| Patch needs improvement: | set |
|---|
by , 18 years ago
| Attachment: | django-date-filter.patch added |
|---|
patch that implements 'x' and 'X' to access the DATE_FORMAT and DATETIME_FORMAT
by , 18 years ago
| 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 by , 18 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 , 18 years ago
| Cc: | 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 , 18 years ago
| 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 by , 17 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 , 17 years ago
| Component: | Template system → Internationalization |
|---|---|
| Keywords: | i18n-rf added |
| milestone: | → post-1.0 |
follow-up: 12 comment:7 by , 17 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:9 by , 16 years ago
| Keywords: | i18n-fixed added; datetime filter i18n-rf removed |
|---|---|
| Owner: | changed from to |
Fixed in branches/soc2009/i18n-improvements.
comment:10 by , 16 years ago
| Triage Stage: | Accepted → Fixed on a branch |
|---|
comment:11 by , 16 years ago
| 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 by , 16 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 , 14 years ago
| Cc: | 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
dateandtimefilters and thedatefilter 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_FORMATandDEFAULT_DATETIME_FORMATwith thedatefilter, I would guess.