#14042: DATE_FORMAT and DATETIME_FORMAT are ignored
-----------------------------------------------+----------------------------
Reporter: bendavis78 | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: 1.2
Keywords: DATE_FORMAT DATETIME_FORMAT admin | Stage: Unreviewed
Has_patch: 0 |
-----------------------------------------------+----------------------------
This is the same bug that was reported in #2203, however #2203 was closed
during the I18N refactoring, even though the bug has not been completely
fixed.
Here's the problem as it exists now. The admin change list calls
django.utils.formats.localize() on date fields. This function, in turn,
calls date_format() in the same module. The problem is that this is only
called in the condition that USE_I10N is set to True. Otherwise, it
simply returns the raw value:
{{{
#!python
def localize(value):
"""
Checks if value is a localizable type (date, number...) and returns it
formatted as a string using current locale format
"""
if settings.USE_L10N:
if isinstance(value, (decimal.Decimal, float, int)):
return number_format(value)
elif isinstance(value, datetime.datetime):
return date_format(value, 'DATETIME_FORMAT')
elif isinstance(value, datetime.date):
return date_format(value)
elif isinstance(value, datetime.time):
return time_format(value, 'TIME_FORMAT')
return value
}}}
The date_format() function, however, already takes care of handing
USE_I10N correctly via get_format():
{{{
#!python
def date_format(value, format=None):
"""
Formats a datetime.date or datetime.datetime object using a
localizable format
"""
return dateformat.format(value, get_format(format or 'DATE_FORMAT'))
def get_format(format_type):
"""
For a specific format type, returns the format for the current
language (locale), defaults to the format in the settings.
format_type is the name of the format, e.g. 'DATE_FORMAT'
"""
format_type = smart_str(format_type)
if settings.USE_L10N:
for module in get_format_modules():
try:
return getattr(module, format_type)
except AttributeError:
pass
return getattr(settings, format_type)
}}}
... so the condition in localize() is not really needed. If we remove
that condition, the problem is fixed. DATE_FORMAT and DATETIME_FORMAT
from settings now works.
--
Ticket URL: <http://code.djangoproject.com/ticket/14042>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.