Contrary to the docs at
http://www.djangoproject.com/documentation/settings/
,
changing TIME_FORMAT, DATE_FORMAT and DATETIME_FORMAT does not influence admin pages in any way.
These were added in
[1115]
but apparently got lost during magic-removal.
(
2.7 KB
) - added by
bahamut@…
18 years ago
.
Settings file for my application. Date and time formats are not respected in admin site.
Download all attachments as:
Does the translated catalog you are using (
pl.po
?) specify these technical IDs
(
TIME_FORMAT
,
DATE_FORMAT
and
DATETIME_FORMAT
)?
This should be working, the code that appears in
contrib/admin/views/main.py
in the
[1115]
patchset
now lives in
contrib/admin/templatetags/admin_list.py
and calls the
utils/translation.py:get_date_formats()
function. That function uses the fomat strings specified in your
xx.po
if any and fallback to the values specified in
global-settings.py
/your
settings.py
.
Seee also
[3055]
I'm not sure how it can work intuitively -- that is, the date and time format settings applying to the admin site and other translated areas properly.
For example, taking the code from the admin site.
source:trunk/django/contrib/admin/templatetags/admin_list.py line 138
elif isinstance(f, models.DateField) or isinstance(f, models.TimeField):
if field_val:
(date_format, datetime_format, time_format) = get_date_formats()
if isinstance(f, models.DateTimeField):
result_repr = capfirst(dateformat.format(field_val, datetime_format))
elif isinstance(f, models.TimeField):
result_repr = capfirst(dateformat.time_format(field_val, time_format))
else:
result_repr = capfirst(dateformat.format(field_val, date_format))
If we look at get_date_formats:
source:trunk/django/utils/translation/trans_real.py line 355
def get_date_formats():
This function checks whether translation files provide a translation for some
technical message ID to store date and time formats. If it doesn't contain
one, the formats provided in the settings will be used.
from django.conf import settings
date_format = _('DATE_FORMAT')
datetime_format = _('DATETIME_FORMAT')
time_format = _('TIME_FORMAT')
if date_format == 'DATE_FORMAT':
date_format = settings.DATE_FORMAT
if datetime_format == 'DATETIME_FORMAT':
datetime_format = settings.DATETIME_FORMAT
if time_format == 'TIME_FORMAT':
time_format = settings.TIME_FORMAT
return date_format, datetime_format, time_format
It would seem we'll always get the format from the translation files, not from the settings.
Correct source links are
- source:django/trunk/django/contrib/admin/templatetags/admin_list.py line 138
- source:django/trunk/django/utils/translation/trans_real.py line 355
I should also mention that, as of r3327, setting USE_I18N to False in your settings file will happily blow up the admin site, with the following exception being generated:
Exception Type: AttributeError
Exception Value: 'module' object has no attribute 'get_language_bidi'
Exception Location: /opt/local/lib/python2.4/site-packages/django/core/context_processors.py in i18n, line 41
This might be worth posting as a new ticket. However, this is a separate issue and I believe date and time formats should be configurable outside the scope or control of the localization files. There are arguably legitimate reasons for this (e.g. an application for the US military might require to use the 24 hours time format, while the locale would stil be en-us).
Exception Type: AttributeError
Exception Value: 'module' object has no attribute 'get_language_bidi'
Exception Location: /opt/local/lib/python2.4/site-packages/django/core/context_processors.py in i18n, line 41
On one level, we *should* be getting the format from the translation files, in almost all cases. This is because the developer/designer of the original presentation is not going to be up to speed on all the subtleties and traditions of time presentation in all the locales, whereas the translator will know how times are normally presented in their particular language (and the translator and designer should be working together on the tricky cases).
So there is a design problem here: allowing control of time presentation information via the settings file does not interact well with localisation. I'm not sure what a solution is to this one yet, since I only just noticed this ticket. But it's not a clear bug, to my mind, at the moment. Needs some more thought.
The example of wanting to force time to always be in military time, for example, is a case where the timezone presentation in each case should be translated to use the 24-hour presentation. However, that is a separate issue in any case (since it enters the realm of project-wide translation files overriding core translations, which is something we cannot handle at the moment). So let's not have any more discussion of that in this ticket, please.
In my mind this is a bug. My reasoning is as follows: In every language there are many different (but correct) ways in which to display a date. Although one way may be considered a default, surely there are many ways that are valid. In order to change the default date display on one app, I have to provide a custom translation?
The triage state for this ticket is "Design decision needed". Something that needs design work is not a candidate for 1.0.3. You might consider asking your question on the django-users list; I do not know if there is any good answer but the audience there is far larger than here so you'd have a better chance of getting a useful answer.
The irony is that even this Trac is not well configured - the dates are listed using US locale instead of something more word-ready like ISO 8601.
Also I strongly recommend to change the *defaults* to use ISO 8601.
When should we see this in trunk?
if date_format == 'DATE_FORMAT':
date_format = settings.DATE_FORMAT
if datetime_format == 'DATETIME_FORMAT':
datetime_format = settings.DATETIME_FORMAT
if time_format == 'TIME_FORMAT':
time_format = settings.TIME_FORMAT
if settings.DATE_FORMAT:
date_format = settings.DATE_FORMAT
if settings.DATETIME_FORMAT:
datetime_format = settings.DATETIME_FORMAT
if settings.TIME_FORMAT:
time_format = settings.TIME_FORMAT
then it will use the format from setting.
(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.