Refs #32987 -- Refactored out get_template_tag_modules().

This commit is contained in:
Daniel Fairhead 2021-08-06 09:36:30 +01:00 committed by Mariusz Felisiak
parent 7ef0bc922c
commit b98394fa62
1 changed files with 19 additions and 10 deletions

View File

@ -84,18 +84,16 @@ def reraise(exc, backend):
raise new from exc
def get_installed_libraries():
def get_template_tag_modules():
"""
Return the built-in template tag libraries and those from installed
applications. Libraries are stored in a dictionary where keys are the
individual module names, not the full module paths. Example:
django.templatetags.i18n is stored as i18n.
Yield (module_name, module_path) pairs for all installed template tag
libraries.
"""
libraries = {}
candidates = ['django.templatetags']
candidates.extend(
'%s.templatetags' % app_config.name
for app_config in apps.get_app_configs())
f'{app_config.name}.templatetags'
for app_config in apps.get_app_configs()
)
for candidate in candidates:
try:
@ -106,9 +104,20 @@ def get_installed_libraries():
if hasattr(pkg, '__path__'):
for name in get_package_libraries(pkg):
libraries[name[len(candidate) + 1:]] = name
yield name[len(candidate) + 1:], name
return libraries
def get_installed_libraries():
"""
Return the built-in template tag libraries and those from installed
applications. Libraries are stored in a dictionary where keys are the
individual module names, not the full module paths. Example:
django.templatetags.i18n is stored as i18n.
"""
return {
module_name: full_name
for module_name, full_name in get_template_tag_modules()
}
def get_package_libraries(pkg):