diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7a845785d9..aece667c35 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -6,6 +6,7 @@ Changelog * Fix: Use a visible border and background color to highlight active formatting in the rich text toolbar (Cassidy Pittman) * Fix: Ensure image focal point box can be removed (Gunnar Scherf) + * Fix: Ensure that Snippets search results correctly use the `index_results.html` or `index_results_template_name` override on initial load (Stefan Hammer) 5.2.1 (16.11.2023) ~~~~~~~~~~~~~~~~~~ diff --git a/docs/releases/5.2.2.md b/docs/releases/5.2.2.md index c6201dcdda..60caa56b81 100644 --- a/docs/releases/5.2.2.md +++ b/docs/releases/5.2.2.md @@ -16,5 +16,6 @@ depth: 1 * Use a visible border and background color to highlight active formatting in the rich text toolbar (Cassidy Pittman) * Ensure image focal point box can be removed (Gunnar Scherf) + * Ensure that Snippets search results correctly use the `index_results.html` or `index_results_template_name` override on initial load (Stefan Hammer) ### Documentation diff --git a/wagtail/snippets/templates/wagtailsnippets/snippets/index.html b/wagtail/snippets/templates/wagtailsnippets/snippets/index.html index 4e861d5077..14df924e77 100644 --- a/wagtail/snippets/templates/wagtailsnippets/snippets/index.html +++ b/wagtail/snippets/templates/wagtailsnippets/snippets/index.html @@ -24,7 +24,7 @@ {% include 'wagtailadmin/shared/header.html' with title=model_opts.verbose_name_plural|capfirst icon=header_icon search_url=search_url base_actions=base_action_locale action_url=action_url_add_snippet action_icon="plus" action_text=action_text_snippet extra_actions=extra_actions search_results_url=index_results_url %}
- {% include "wagtailsnippets/snippets/index_results.html" %} + {% include view.results_template_name|default:"wagtailsnippets/snippets/index_results.html" %}
{% if filters %} {% include "wagtailadmin/shared/filters.html" %} diff --git a/wagtail/snippets/tests/test_viewset.py b/wagtail/snippets/tests/test_viewset.py index 2b1c891319..afd6ac3ea3 100644 --- a/wagtail/snippets/tests/test_viewset.py +++ b/wagtail/snippets/tests/test_viewset.py @@ -876,45 +876,61 @@ class TestCustomTemplates(BaseSnippetViewSetTests): "with app label and model name": ( "add", [], - "wagtailsnippets/snippets/tests/fullfeaturedsnippet/create.html", + [ + "wagtailsnippets/snippets/tests/fullfeaturedsnippet/create.html", + ], ), "with app label": ( "edit", [pk], - "wagtailsnippets/snippets/tests/edit.html", + [ + "wagtailsnippets/snippets/tests/edit.html", + ], ), "without app label and model name": ( "delete", [pk], - "wagtailsnippets/snippets/delete.html", + [ + "wagtailsnippets/snippets/delete.html", + ], ), "override a view that uses a generic template": ( "unpublish", [pk], - "wagtailsnippets/snippets/tests/fullfeaturedsnippet/unpublish.html", + [ + "wagtailsnippets/snippets/tests/fullfeaturedsnippet/unpublish.html", + ], ), - "override with index_template_name": ( + "override with index_template_name and index results template with namespaced template": ( "list", [], - "tests/fullfeaturedsnippet_index.html", + [ + "tests/fullfeaturedsnippet_index.html", + "wagtailsnippets/snippets/tests/fullfeaturedsnippet/index_results.html", + ], ), "override index results template with namespaced template": ( # This is technically the same as the first case, but this ensures that # the index results view can be overridden separately from the index view "list_results", [], - "wagtailsnippets/snippets/tests/fullfeaturedsnippet/index_results.html", + [ + "wagtailsnippets/snippets/tests/fullfeaturedsnippet/index_results.html" + ], ), "override with get_history_template": ( "history", [pk], - "tests/snippet_history.html", + [ + "tests/snippet_history.html", + ], ), } - for case, (view_name, args, template_name) in cases.items(): + for case, (view_name, args, template_names) in cases.items(): with self.subTest(case=case): response = self.client.get(self.get_url(view_name, args=args)) - self.assertTemplateUsed(response, template_name) + for template_name in template_names: + self.assertTemplateUsed(response, template_name) self.assertContains(response, "

An added paragraph

", html=True)