diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-01-13 03:13:39 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-01-13 03:13:39 +0000 |
| commit | 4d2708ff010a573d78759bf9ab9e672a57ad8726 (patch) | |
| tree | 7f00824dc7a85bd76845b7391a178d01c2dbbc06 | |
| parent | 0a0472f51bad24870e2bb6b89595ac922897442e (diff) | |
[1.2.X] Fixed #15024 -- Ensure that choice of L10N format module used is stable given a stable setup of format modules in ll/ and ll_CC/ dirs. Thanks David Reynolds for the report and suggestions leading to the solution.
Backport of [15183] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15184 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/utils/formats.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/i18n/tests.py | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/django/utils/formats.py b/django/utils/formats.py index 7b1d23db33..d0c63fb96f 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -24,7 +24,9 @@ def iter_format_modules(lang): format_locations.append(settings.FORMAT_MODULE_PATH + '.%s') format_locations.reverse() locale = to_locale(lang) - locales = set((locale, locale.split('_')[0])) + locales = [locale] + if '_' in locale: + locales.append(locale.split('_')[0]) for location in format_locations: for loc in locales: try: diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 99f9fe1303..f0ab434712 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -452,6 +452,19 @@ class FormattingTests(TestCase): settings.FORMAT_MODULE_PATH = old_format_module_path deactivate() + def test_iter_format_modules_stability(self): + """ + Tests the iter_format_modules function always yields format modules in + a stable and correct order in presence of both base ll and ll_CC formats. + """ + try: + old_l10n, settings.USE_L10N = settings.USE_L10N, True + en_format_mod = import_module('django.conf.locale.en.formats') + en_gb_format_mod = import_module('django.conf.locale.en_GB.formats') + self.assertEqual(list(iter_format_modules('en-gb')), [en_gb_format_mod, en_format_mod]) + finally: + settings.USE_L10N = old_l10n + class MiscTests(TestCase): |
