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.
pull/10225/head
Andy Chosak 2023-03-09 16:45:06 -05:00 zatwierdzone przez LB (Ben Johnston)
rodzic af57a3eb7e
commit 6eca0004b3
4 zmienionych plików z 12 dodań i 1 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -2,7 +2,7 @@
{% if documents %}
{% if is_searching %}
<h2 role="alert">
{% blocktrans trimmed count counter=documents|length %}
{% blocktrans trimmed count counter=documents.paginator.count %}
There is {{ counter }} match
{% plural %}
There are {{ counter }} matches

Wyświetl plik

@ -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: