Opened 6 years ago

Closed 6 years ago

#14042 closed (duplicate)


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: UI/UX:


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,
            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 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():
                return getattr(module, format_type)
            except AttributeError:
    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)

date_format_settings_fix.diff (1.2 KB) - added by Ben Davis 6 years ago.

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by Ben Davis

comment:1 Changed 6 years ago by Ben Davis

Has patch: set

comment:2 Changed 6 years ago by Karen Tracey

Resolution: duplicate
Status: newclosed

Isn't this #13702?

Note: See TracTickets for help on using tickets.
Back to Top