From 6eca0004b3b0187d52e45b1722b334eea372b77b Mon Sep 17 00:00:00 2001 From: Andy Chosak Date: Thu, 9 Mar 2023 16:45:06 -0500 Subject: [PATCH] Fix paginated results count on document search #10220 Paginated document search results currently always show the number of documents per page instead of the total number of documents in the search results. For example, if a document search (at http://localhost:8000/admin/documents/) returns 100 results, and the results are paginated by 20, the results view always says "There are 20 matches", when it should instead say "There are 100 matches". This commit fixes that bug and adds a unit test to cover it. --- CHANGELOG.txt | 1 + docs/releases/5.0.md | 1 + .../templates/wagtaildocs/documents/results.html | 2 +- wagtail/documents/tests/test_admin_views.py | 9 +++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index da7ba610ff..838a88881b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -41,6 +41,7 @@ Changelog * Fix: Prevent duplicate addition of StreamField blocks with the new block picker (Deepam Priyadarshi) * Fix: Enable partial search on images and documents index view where available (Mng) * Fix: Adopt a no-JavaScript and more accessible solution for option selection in reporting, using HTML only `radio` input fields (Mehul Aggarwal) + * Fix: Ensure that document search results count shows the correct all matches, not the paginate total (Andy Chosak) * Docs: Add code block to make it easier to understand contribution docs (Suyash Singh) * Docs: Add new "Icons" page for icons customisation and reuse across the admin interface (Coen van der Kamp) * Docs: Fix broken formatting for MultiFieldPanel / FieldRowPanel permission kwarg docs (Matt Westcott) diff --git a/docs/releases/5.0.md b/docs/releases/5.0.md index 77a59ee60b..2218d0ef90 100644 --- a/docs/releases/5.0.md +++ b/docs/releases/5.0.md @@ -55,6 +55,7 @@ Support for adding custom validation logic to StreamField blocks has been formal * Prevent duplicate addition of StreamField blocks with the new block picker (Deepam Priyadarshi) * Enable partial search on images and documents index view where available (Mng) * Adopt a no-JavaScript and more accessible solution for option selection in reporting, using HTML only `radio` input fields (Mehul Aggarwal) + * Ensure that document search results count shows the correct all matches, not the paginate total (Andy Chosak) ### Documentation diff --git a/wagtail/documents/templates/wagtaildocs/documents/results.html b/wagtail/documents/templates/wagtaildocs/documents/results.html index 1ec27422dc..ac2a3c49cf 100644 --- a/wagtail/documents/templates/wagtaildocs/documents/results.html +++ b/wagtail/documents/templates/wagtaildocs/documents/results.html @@ -2,7 +2,7 @@ {% if documents %} {% if is_searching %}

- {% blocktrans trimmed count counter=documents|length %} + {% blocktrans trimmed count counter=documents.paginator.count %} There is {{ counter }} match {% plural %} There are {{ counter }} matches diff --git a/wagtail/documents/tests/test_admin_views.py b/wagtail/documents/tests/test_admin_views.py index 6366a8d7c8..cc5c05388c 100644 --- a/wagtail/documents/tests/test_admin_views.py +++ b/wagtail/documents/tests/test_admin_views.py @@ -114,6 +114,15 @@ class TestDocumentIndexView(WagtailTestUtils, TestCase): response.context["documents"].paginator.num_pages, ) + def test_pagination_q(self): + self.make_docs() + + response = self.get({"q": "Test"}) + + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "wagtaildocs/documents/index.html") + self.assertContains(response, "There are 50 matches") + def test_ordering(self): orderings = ["title", "-created_at"] for ordering in orderings: