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