Code

Ticket #15129: 15129.2.diff

File 15129.2.diff, 2.1 KB (added by tonnzor, 3 years ago)

Ramiro patch with fixed iterator -> list

Line 
1diff -r 030518391c49 django/utils/formats.py
2--- a/django/utils/formats.py   Mon Jan 24 20:35:46 2011 +0000
3+++ b/django/utils/formats.py   Mon Jan 24 18:33:48 2011 -0300
4@@ -36,12 +36,12 @@
5 
6 def get_format_modules(reverse=False):
7     """
8-    Returns an iterator over the format modules found
9+    Returns a list of the format modules found
10     """
11     lang = get_language()
12     modules = _format_modules_cache.setdefault(lang, list(iter_format_modules(lang)))
13     if reverse:
14-        modules.reverse()
15+        return list(reversed(modules))
16     return modules
17 
18 def get_format(format_type, lang=None, use_l10n=None):
19diff -r 030518391c49 tests/regressiontests/i18n/tests.py
20--- a/tests/regressiontests/i18n/tests.py   Mon Jan 24 20:35:46 2011 +0000
21+++ b/tests/regressiontests/i18n/tests.py   Mon Jan 24 18:33:48 2011 -0300
22@@ -9,7 +9,7 @@
23 from django.conf import settings
24 from django.template import Template, Context
25 from django.utils.formats import (get_format, date_format, time_format,
26-    localize, localize_input, iter_format_modules)
27+    localize, localize_input, iter_format_modules, get_format_modules)
28 from django.utils.importlib import import_module
29 from django.utils.numberformat import format as nformat
30 from django.utils.safestring import mark_safe, SafeString, SafeUnicode
31@@ -495,6 +495,19 @@
32         finally:
33             settings.USE_L10N = old_l10n
34 
35+    def test_get_format_modules_stability(self):
36+        activate('de')
37+        old_format_module_path = settings.FORMAT_MODULE_PATH
38+        settings.FORMAT_MODULE_PATH = 'regressiontests.i18n.other.locale'
39+        try:
40+            settings.USE_L10N = True
41+            old = "%r" % get_format_modules(reverse=True)
42+            new = "%r" % get_format_modules(reverse=True) # second try
43+            self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.')
44+        finally:
45+            settings.FORMAT_MODULE_PATH = old_format_module_path
46+            deactivate()
47+
48     def test_localize_templatetag_and_filter(self):
49         """
50         Tests the {% localize %} templatetag