From 53c6bf06900612f6dc832663844a41c78d497c3a Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 11 Oct 2023 12:13:40 +0100 Subject: [PATCH] Add pagination information to page title column header --- .../pages/listing/_page_title_column_header.html | 7 +++++++ .../admin/templates/wagtailadmin/tables/column_header.html | 1 + wagtail/admin/tests/pages/test_explorer_view.py | 3 +++ wagtail/admin/ui/tables/pages.py | 7 +++++++ 4 files changed, 18 insertions(+) create mode 100644 wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_column_header.html diff --git a/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_column_header.html b/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_column_header.html new file mode 100644 index 0000000000..d781e0ecfb --- /dev/null +++ b/wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_column_header.html @@ -0,0 +1,7 @@ +{% extends "wagtailadmin/tables/column_header.html" %} + +{% block after_label %} + {% if page_obj %} + {{ page_obj.start_index }}-{{ page_obj.end_index }} of {{ page_obj.paginator.count }} + {% endif %} +{% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/tables/column_header.html b/wagtail/admin/templates/wagtailadmin/tables/column_header.html index a3c02fcdf0..6f1d8fb293 100644 --- a/wagtail/admin/templates/wagtailadmin/tables/column_header.html +++ b/wagtail/admin/templates/wagtailadmin/tables/column_header.html @@ -17,4 +17,5 @@ {% else %} {{ column.label }} {% endif %} + {% block after_label %}{% endblock %} diff --git a/wagtail/admin/tests/pages/test_explorer_view.py b/wagtail/admin/tests/pages/test_explorer_view.py index e1ca780a55..1bf357538b 100644 --- a/wagtail/admin/tests/pages/test_explorer_view.py +++ b/wagtail/admin/tests/pages/test_explorer_view.py @@ -59,6 +59,7 @@ class TestPageExplorer(WagtailTestUtils, TestCase): self.assertEqual( page_ids, [self.new_page.id, self.old_page.id, self.child_page.id] ) + self.assertContains(response, "1-3 of 3") def test_explore_root(self): response = self.client.get(reverse("wagtailadmin_explore_root")) @@ -250,6 +251,7 @@ class TestPageExplorer(WagtailTestUtils, TestCase): # Check that we got the correct page self.assertEqual(response.context["page_obj"].number, 2) + self.assertContains(response, "51-100 of 153") def test_pagination_invalid(self): self.make_pages() @@ -412,6 +414,7 @@ class TestPageExplorer(WagtailTestUtils, TestCase): page_ids = [page.id for page in response.context["pages"]] self.assertEqual(page_ids, [self.old_page.id]) + self.assertContains(response, "1-1 of 1") def test_search_searches_descendants(self): response = self.client.get(reverse("wagtailadmin_explore_root"), {"q": "old"}) diff --git a/wagtail/admin/ui/tables/pages.py b/wagtail/admin/ui/tables/pages.py index af04e523c0..adffa0c215 100644 --- a/wagtail/admin/ui/tables/pages.py +++ b/wagtail/admin/ui/tables/pages.py @@ -5,9 +5,15 @@ from wagtail.admin.ui.tables import BaseColumn, BulkActionsCheckboxColumn, Colum class PageTitleColumn(BaseColumn): + header_template_name = "wagtailadmin/pages/listing/_page_title_column_header.html" cell_template_name = "wagtailadmin/pages/listing/_page_title_cell.html" classname = "title" + def get_header_context_data(self, parent_context): + context = super().get_header_context_data(parent_context) + context["page_obj"] = parent_context.get("page_obj") + return context + def get_cell_context_data(self, instance, parent_context): context = super().get_cell_context_data(instance, parent_context) context["page_perms"] = instance.permissions_for_user( @@ -132,4 +138,5 @@ class PageTable(Table): context = super().get_context_data(parent_context) context["show_locale_labels"] = self.show_locale_labels context["perms"] = parent_context.get("perms") + context["page_obj"] = parent_context.get("page_obj") return context