#15129: Invalid order of applying formats -------------------------------------------+-------------------------------- Reporter: tonnzor | Owner: nobody Status: new | Milestone: 1.3 Component: Internationalization | Version: 1.2 Resolution: | Keywords: Stage: Accepted | Has_patch: 1 Needs_docs: 0 | Needs_tests: 1 Needs_better_patch: 1 | -------------------------------------------+-------------------------------- Comment (by tonnzor):
What's wrong with current patch? I may improve it if needed. The only thing I found inconsistent is that new code returns list, not an iterator. However, previous version returned list too and making it return iterator would require to fix django/views/i18n.py file too: {{{ --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -1,4 +1,5 @@ import os +import itertools import gettext as gettext_module from django import http @@ -47,7 +48,7 @@ 'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS' ) result = {} - for module in [settings] + get_format_modules(reverse=True): + for module in itertools.chain([settings], get_format_modules(reverse=True)): for attr in FORMAT_SETTINGS: try: result[attr] = getattr(module, attr) --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -39,7 +39,7 @@ lang = get_language() modules = _format_modules_cache.setdefault(lang, list(iter_format_modules(lang))) if reverse: - modules.reverse() + return reversed(modules) return modules def get_format(format_type): }}} As of the test - we'll need a project with FORMAT_MODULE_PATH set and formats file existing. Then test is quite simple: {{{ from django.utils import unittest from django.utils.formats import get_format_modules class MyTestCase(unittest.TestCase): def setUp(self): pass def testPreservedOrder(self): old = "%r" % get_format_modules(reverse=True) # serialize to prevent changing new = "%r" % get_format_modules(reverse=True) # second try self.assertEqual(new, old, 'get_formats_modules result must be the same during calls') }}} That check (that result changes during consequent calls) proves the issue on non-patched system. -- Ticket URL: <http://code.djangoproject.com/ticket/15129#comment:6> 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 django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.