1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #24128 -- Made admindocs TemplateDetailView respect template_loaders.

Co-Authored-By: Author: Alexander Lazarević <laza@e11bits.com>
This commit is contained in:
Kris Avi 2016-10-26 20:26:36 +03:00 committed by Mariusz Felisiak
parent 1df8983aa3
commit b7154f811f
3 changed files with 21 additions and 2 deletions

View File

@ -404,8 +404,13 @@ class TemplateDetailView(BaseAdminDocsView):
# Non-trivial TEMPLATES settings aren't supported (#24125). # Non-trivial TEMPLATES settings aren't supported (#24125).
pass pass
else: else:
# This doesn't account for template loaders (#24128). directories = list(default_engine.dirs)
for index, directory in enumerate(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)) template_file = Path(safe_join(directory, template))
if template_file.exists(): if template_file.exists():
template_contents = template_file.read_text() template_contents = template_file.read_text()

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Template for Test</title>
</head>
<body></body>
</html>

View File

@ -138,6 +138,12 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
html=True, 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): def test_missing_docutils(self):
utils.docutils_is_available = False utils.docutils_is_available = False
try: try: