From b7154f811f0c01757346f88ee006c8f2034acee3 Mon Sep 17 00:00:00 2001 From: Kris Avi Date: Wed, 26 Oct 2016 20:26:36 +0300 Subject: [PATCH] Fixed #24128 -- Made admindocs TemplateDetailView respect template_loaders. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Author: Alexander Lazarević --- django/contrib/admindocs/views.py | 9 +++++++-- tests/admin_docs/templates/view_for_loader_test.html | 8 ++++++++ tests/admin_docs/test_views.py | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/admin_docs/templates/view_for_loader_test.html diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index 4f970e89b3..5c18d676f2 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -404,8 +404,13 @@ class TemplateDetailView(BaseAdminDocsView): # 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() diff --git a/tests/admin_docs/templates/view_for_loader_test.html b/tests/admin_docs/templates/view_for_loader_test.html new file mode 100644 index 0000000000..12130c54cd --- /dev/null +++ b/tests/admin_docs/templates/view_for_loader_test.html @@ -0,0 +1,8 @@ + + + + + Template for Test + + + diff --git a/tests/admin_docs/test_views.py b/tests/admin_docs/test_views.py index bf469181b3..ef7fde1bf9 100644 --- a/tests/admin_docs/test_views.py +++ b/tests/admin_docs/test_views.py @@ -138,6 +138,12 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase): 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") + def test_missing_docutils(self): utils.docutils_is_available = False try: