-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing FORMAT_MODULE_PATH setting to be list of paths. #1236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -46,21 +46,29 @@ def iter_format_modules(lang, format_module_path=None): | ||
""" | """ | ||
Does the heavy lifting of finding format modules. | Does the heavy lifting of finding format modules. | ||
""" | """ | ||
if check_for_language(lang): | if not check_for_language(lang): | ||
format_locations = ['django.conf.locale.%s'] | return | ||
if format_module_path: |
|
||
format_locations.append(format_module_path + '.%s') | if format_module_path is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow, the parameter However, that parameter must be there for some reason and other people might use it in their codebases, so I changed the code slightly to honour the parameter again. If the parameter is given, we ignore the setting. @timgraham this way the failing test passes. Do we need to document that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would check |
|||
format_locations.reverse() | format_module_path = settings.FORMAT_MODULE_PATH | ||
locale = to_locale(lang) |
|
||
locales = [locale] | format_locations = [] | ||
if '_' in locale: | if format_module_path: | ||
locales.append(locale.split('_')[0]) | if isinstance(format_module_path, six.string_types): | ||
for location in format_locations: | format_module_path = [format_module_path] | ||
for loc in locales: | for path in format_module_path: | ||
try: | format_locations.append(path + '.%s') | ||
yield import_module('%s.formats' % (location % loc)) | format_locations.append('django.conf.locale.%s') | ||
except ImportError: | locale = to_locale(lang) | ||
pass | 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): | def get_format_modules(lang=None, reverse=False): | ||
|
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -1378,6 +1378,20 @@ like:: | ||
__init__.py | __init__.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I described the new way to use this setting in the docs. |
|||
formats.py | formats.py | ||
|
|
||
.. versionchanged:: 1.8 | |||
|
|||
You can also set this setting to a list of Python paths, for example:: | |||
|
|||
FORMAT_MODULE_PATH = [ | |||
'mysite.formats', | |||
'some_app.formats', | |||
] | |||
|
|||
When Django searches for a certain format, it will go through all given | |||
Python paths until it finds a module that actually defines the given | |||
format. This means that formats defined in packages farther up in the list | |||
will take precendence over the same formats in packages farther down. | |||
|
|||
Available formats are :setting:`DATE_FORMAT`, :setting:`TIME_FORMAT`, | Available formats are :setting:`DATE_FORMAT`, :setting:`TIME_FORMAT`, | ||
:setting:`DATETIME_FORMAT`, :setting:`YEAR_MONTH_FORMAT`, | :setting:`DATETIME_FORMAT`, :setting:`YEAR_MONTH_FORMAT`, | ||
:setting:`MONTH_DAY_FORMAT`, :setting:`SHORT_DATE_FORMAT`, | :setting:`MONTH_DAY_FORMAT`, :setting:`SHORT_DATE_FORMAT`, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reversed the if-check at the beginning so that we can un-indent the whole code by one. Much nicer to read that way.