summaryrefslogtreecommitdiff
path: root/django/utils/formats.py
diff options
context:
space:
mode:
authorMartin Brochhaus <mbrochh@gmail.com>2014-05-19 13:23:45 +0800
committerTim Graham <timograham@gmail.com>2014-05-21 07:35:47 -0400
commitbb0a9a070b9570c85bcb17346dae6513e4ba6e76 (patch)
tree17c9f8c4cd129536b5cc583d5da8b82967a58521 /django/utils/formats.py
parentdfeef8e1472eadf7c3d350f6ee7328352e5953f0 (diff)
downloaddjango-bb0a9a070b9570c85bcb17346dae6513e4ba6e76.tar.gz
Fixed #20477: Allowed list of modules for FORMAT_MODULE_PATH
Previously the FORMAT_MODULE_PATH setting only accepted one string (dotted module path). A feature has been added to also allow a list of strings. This is useful when using several reusable third party apps that define new formats. We can now use them all and we can even override some of the formats by providing a project-wide format module.
Diffstat (limited to 'django/utils/formats.py')
-rw-r--r--django/utils/formats.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/django/utils/formats.py b/django/utils/formats.py
index fc68179f3a..521ab5c763 100644
--- a/django/utils/formats.py
+++ b/django/utils/formats.py
@@ -46,21 +46,29 @@ def iter_format_modules(lang, format_module_path=None):
"""
Does the heavy lifting of finding format modules.
"""
- if check_for_language(lang):
- format_locations = ['django.conf.locale.%s']
- if format_module_path:
- format_locations.append(format_module_path + '.%s')
- format_locations.reverse()
- locale = to_locale(lang)
- locales = [locale]
- if '_' in locale:
- locales.append(locale.split('_')[0])
- for location in format_locations:
- for loc in locales:
- try:
- yield import_module('%s.formats' % (location % loc))
- except ImportError:
- pass
+ if not check_for_language(lang):
+ return
+
+ if format_module_path is None:
+ format_module_path = settings.FORMAT_MODULE_PATH
+
+ format_locations = []
+ if format_module_path:
+ if isinstance(format_module_path, six.string_types):
+ format_module_path = [format_module_path]
+ for path in format_module_path:
+ format_locations.append(path + '.%s')
+ format_locations.append('django.conf.locale.%s')
+ locale = to_locale(lang)
+ locales = [locale]
+ if '_' in locale:
+ locales.append(locale.split('_')[0])
+ for location in format_locations:
+ for loc in locales:
+ try:
+ yield import_module('%s.formats' % (location % loc))
+ except ImportError:
+ pass
def get_format_modules(lang=None, reverse=False):