Opened 14 years ago
Closed 14 years ago
#14042 closed (duplicate)
DATE_FORMAT and DATETIME_FORMAT are ignored
Reported by: | Ben Davis | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.2 |
Severity: | Keywords: | DATE_FORMAT DATETIME_FORMAT admin | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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:
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():
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.
Attachments (1)
Change History (3)
by , 14 years ago
Attachment: | date_format_settings_fix.diff added |
---|
comment:1 by , 14 years ago
Has patch: | set |
---|
comment:2 by , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Isn't this #13702?