diff options
| author | Shreya Bamne <shreya.bamne@gmail.com> | 2021-08-03 15:20:49 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-20 11:15:47 +0200 |
| commit | 004b4620f6f4ad87261e149898940f2dcd5757ef (patch) | |
| tree | 233f505d749bbd26208bc5b6236df629942ec5fe /django | |
| parent | b98394fa62753c867a287c2839696695557281a5 (diff) | |
Fixed #32987 -- Added system check for template tag modules with the same name.
Co-authored-by: Daniel Fairhead <daniel@dev.ngo>
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/checks/templates.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/django/core/checks/templates.py b/django/core/checks/templates.py index 8c4b7c172b..14325bd3e0 100644 --- a/django/core/checks/templates.py +++ b/django/core/checks/templates.py @@ -1,6 +1,8 @@ import copy +from collections import defaultdict from django.conf import settings +from django.template.backends.django import get_template_tag_modules from . import Error, Tags, register @@ -13,6 +15,10 @@ E002 = Error( "'string_if_invalid' in TEMPLATES OPTIONS must be a string but got: {} ({}).", id="templates.E002", ) +E003 = Error( + '{} is used for multiple template tag modules: {}', + id='templates.E003', +) @register(Tags.templates) @@ -33,3 +39,29 @@ def check_string_if_invalid_is_string(app_configs, **kwargs): error.msg = error.msg.format(string_if_invalid, type(string_if_invalid).__name__) errors.append(error) return errors + + +@register(Tags.templates) +def check_for_template_tags_with_the_same_name(app_configs, **kwargs): + errors = [] + libraries = defaultdict(list) + + for conf in settings.TEMPLATES: + custom_libraries = conf.get('OPTIONS', {}).get('libraries', {}) + for module_name, module_path in custom_libraries.items(): + libraries[module_name].append(module_path) + + for module_name, module_path in get_template_tag_modules(): + libraries[module_name].append(module_path) + + for library_name, items in libraries.items(): + if len(items) > 1: + errors.append(Error( + E003.msg.format( + repr(library_name), + ', '.join(repr(item) for item in items), + ), + id=E003.id, + )) + + return errors |
