﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15129	Invalid order of applying formats	Artem Skoretskiy	nobody	"I found that DATE_INPUT_FORMATS used for JS I18N is not format I defined in app/formats/*/formats.py file (FORMAT_MODULE_PATH = 'app.formats')

Django version is 1.2.4

I found that get_formats uses invalid order of formats - so format I defined is being overwritten by Django's default ones.

That is serious bug as Django JS uses different formatting than server-side code.


To prove that I changed file django/views/i18n.py to debug the issue:
{{{
def get_formats():
    """"""
    Returns all formats strings required for i18n to work
    """"""
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    modules = [settings] + get_format_modules(reverse=True) # DEBUG
    log = '%r:\n' % modules # DEBUG
    for module in modules:
        for attr in FORMAT_SETTINGS:
            try:
                if attr == 'DATE_INPUT_FORMATS': # DEBUG
                    log += ""    %r from %r\n"" % (getattr(module, attr, None), module) #DEBUG
                result[attr] = getattr(module, attr)
            except AttributeError:
                pass
    log += ""=> %r from %r"" % (result.get('DATE_INPUT_FORMATS'), module) # DEBUG
    if result.get('DATE_INPUT_FORMATS') != ('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y'): # DEBUG
        logging.getLogger('coupon.localebug').error(log) # DEBUG

    # remaining code is cut
}}}

That's the output I got:
{{{
[<django.conf.LazySettings object at 0x2359fd0>, <module 'app.formats.fr.formats' from '/XXX/app/formats/fr/formats.pyc'>, <module 'django.conf.locale.fr.formats' from '/XXX/pyenv/lib/python2.5/site-packages/django/conf/locale/fr/formats.pyc'>]:
    ('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y', '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y') from <django.conf.LazySettings object at 0x2359fd0>
    ('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y') from <module 'app.formats.fr.formats' from '/XXX/app/formats/fr/formats.pyc'>
    ('%d/%m/%Y', '%d/%m/%y', '%d.%m.%Y', '%d.%m.%y', '%Y-%m-%d', '%y-%m-%d') from <module 'django.conf.locale.fr.formats' from '/XXX/pyenv/lib/python2.5/site-packages/django/conf/locale/fr/formats.pyc'>
=>  ('%d/%m/%Y', '%d/%m/%y', '%d.%m.%Y', '%d.%m.%y', '%Y-%m-%d', '%y-%m-%d') from <module 'django.conf.locale.fr.formats' from '/XXX/pyenv/lib/python2.5/site-packages/django/conf/locale/fr/formats.pyc'>
}}}

That means that my format is used, but it is not the last in the order, so it is being overwritten."		closed	Internationalization	1.2		fixed		Artem Skoretskiy <tonn81@…>	Ready for checkin	1	0	0	1	0	0
