Skip to content

Commit

Permalink
Fixed #24128 -- Made admindocs TemplateDetailView respect template_lo…
Browse files Browse the repository at this point in the history
…aders.

Co-Authored-By: Author: Alexander Lazarević <[email protected]>
  • Loading branch information
2 people authored and felixxm committed Jan 29, 2024
1 parent 1df8983 commit b7154f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions django/contrib/admindocs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,13 @@ def get_context_data(self, **kwargs):
# Non-trivial TEMPLATES settings aren't supported (#24125).
pass
else:
# This doesn't account for template loaders (#24128).
for index, directory in enumerate(default_engine.dirs):
directories = list(default_engine.dirs)
for loader in default_engine.template_loaders:
if hasattr(loader, "get_dirs"):
for dir_ in loader.get_dirs():
if dir_ not in directories:
directories.append(dir_)
for index, directory in enumerate(directories):
template_file = Path(safe_join(directory, template))
if template_file.exists():
template_contents = template_file.read_text()
Expand Down
8 changes: 8 additions & 0 deletions tests/admin_docs/templates/view_for_loader_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Template for Test</title>
</head>
<body></body>
</html>
6 changes: 6 additions & 0 deletions tests/admin_docs/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def test_template_detail(self):
html=True,
)

def test_template_detail_loader(self):
response = self.client.get(
reverse("django-admindocs-templates", args=["view_for_loader_test.html"])
)
self.assertContains(response, "view_for_loader_test.html</code></li>")

def test_missing_docutils(self):
utils.docutils_is_available = False
try:
Expand Down

0 comments on commit b7154f8

Please sign in to comment.