Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #15129 -- Fixed stability of data input/output L10N for…

…mat modules priority order. Thanks tonnzor for the report and fix.

Backport of [15402] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15403 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5f2f0113db4489de4b2260bf3365b514418ad0b8 1 parent f6606da
Ramiro Morales authored February 03, 2011
4  django/utils/formats.py
@@ -36,12 +36,12 @@ def iter_format_modules(lang):
36 36
 
37 37
 def get_format_modules(reverse=False):
38 38
     """
39  
-    Returns an iterator over the format modules found
  39
+    Returns a list of the format modules found
40 40
     """
41 41
     lang = get_language()
42 42
     modules = _format_modules_cache.setdefault(lang, list(iter_format_modules(lang)))
43 43
     if reverse:
44  
-        modules.reverse()
  44
+        return list(reversed(modules))
45 45
     return modules
46 46
 
47 47
 def get_format(format_type):
16  tests/regressiontests/i18n/tests.py
@@ -8,7 +8,8 @@
8 8
 from django.conf import settings
9 9
 from django.template import Template, Context
10 10
 from django.test import TestCase
11  
-from django.utils.formats import get_format, date_format, time_format, localize, localize_input, iter_format_modules
  11
+from django.utils.formats import (get_format, date_format, time_format,
  12
+    localize, localize_input, iter_format_modules, get_format_modules)
12 13
 from django.utils.numberformat import format as nformat
13 14
 from django.utils.safestring import mark_safe, SafeString, SafeUnicode
14 15
 from django.utils.translation import (ugettext, ugettext_lazy, activate,
@@ -466,6 +467,19 @@ def test_iter_format_modules_stability(self):
466 467
         finally:
467 468
             settings.USE_L10N = old_l10n
468 469
 
  470
+    def test_get_format_modules_stability(self):
  471
+        activate('de')
  472
+        old_format_module_path = settings.FORMAT_MODULE_PATH
  473
+        settings.FORMAT_MODULE_PATH = 'regressiontests.i18n.other.locale'
  474
+        try:
  475
+            settings.USE_L10N = True
  476
+            old = "%r" % get_format_modules(reverse=True)
  477
+            new = "%r" % get_format_modules(reverse=True) # second try
  478
+            self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.')
  479
+        finally:
  480
+            settings.FORMAT_MODULE_PATH = old_format_module_path
  481
+            deactivate()
  482
+
469 483
 
470 484
 class MiscTests(TestCase):
471 485
 

0 notes on commit 5f2f011

Please sign in to comment.
Something went wrong with that request. Please try again.