diff options
| author | Daniel Fairhead <daniel@dev.ngo> | 2021-08-06 09:36:30 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-20 09:40:15 +0200 |
| commit | b98394fa62753c867a287c2839696695557281a5 (patch) | |
| tree | 1cf6ec2518935595d99c1754aed2baa15db2ce68 /django/template | |
| parent | 7ef0bc922c0a78667ed8cbf5f85845b627ccbdf8 (diff) | |
Refs #32987 -- Refactored out get_template_tag_modules().
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/backends/django.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/django/template/backends/django.py b/django/template/backends/django.py index d99631cc19..48257e5e4e 100644 --- a/django/template/backends/django.py +++ b/django/template/backends/django.py @@ -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): |
