Update pagination behaviour on page chooser to match Django standard

pull/10533/head
Matt Westcott 2023-06-10 01:29:07 +01:00
rodzic 5e2597cb40
commit fbf1ebe346
2 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -298,13 +298,13 @@ class TestChooserBrowseChild(WagtailTestUtils, TestCase):
self.setup_pagination_test_data()
response = self.get({"p": "foo"})
self.assertEqual(response.context["pagination_page"].number, 1)
self.assertEqual(response.status_code, 404)
def test_pagination_out_of_range_page(self):
self.setup_pagination_test_data()
response = self.get({"p": 100})
self.assertEqual(response.context["pagination_page"].number, 5)
self.assertEqual(response.status_code, 404)
class TestChooserSearch(WagtailTestUtils, TransactionTestCase):

Wyświetl plik

@ -1,7 +1,7 @@
import re
from django.conf import settings
from django.core.paginator import Paginator
from django.core.paginator import InvalidPage, Paginator
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
@ -342,7 +342,10 @@ class BrowseView(View):
# We apply pagination first so we don't need to walk the entire list
# in the block below
paginator = Paginator(pages, per_page=25)
pages = paginator.get_page(request.GET.get("p"))
try:
pages = paginator.page(request.GET.get("p", 1))
except InvalidPage:
raise Http404
# Annotate each page with can_choose/can_decend flags
for page in pages: