Skip to content
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

Fixed #1780 -- Adjusted system check to allow for nested template loa… #1783

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions debug_toolbar/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,26 @@ def check_template_config(config):
included in the loaders.
If custom loaders are specified, then APP_DIRS must be True.
"""

def flat_loaders(loaders):
"""
Recursively flatten the settings list of template loaders.

Check for (loader, [child_loaders]) tuples.
Django's default cached loader uses this pattern.
"""
for loader in loaders:
if isinstance(loader, tuple):
yield loader[0]
yield from flat_loaders(loader[1])
else:
yield loader

app_dirs = config.get("APP_DIRS", False)
loaders = config.get("OPTIONS", {}).get("loaders", None)
if loaders:
loaders = list(flat_loaders(loaders))

# By default the app loader is included.
has_app_loaders = (
loaders is None or "django.template.loaders.app_directories.Loader" in loaders
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Change log
Pending
-------

* Adjusted app directories system check to allow for nested template loaders.

4.1.0 (2023-05-15)
------------------

Expand Down
29 changes: 29 additions & 0 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,32 @@ def test_check_w006_invalid(self):
)
def test_check_w006_valid(self):
self.assertEqual(run_checks(), [])

@override_settings(
TEMPLATES=[
{
"NAME": "use_loaders",
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": False,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
),
],
},
},
]
)
def test_check_w006_valid_nested_loaders(self):
self.assertEqual(run_checks(), [])