Fix is_paginated to correctly honour get_paginate_by methods returning None

Checking self.paginate_by here is not valid, as that doesn't get updated from the class-level value in the case that get_paginate_by is overridden. Django's BaseListView provides an is_paginated variable, so this could be omitted entirely - however, this returns False in the case that a view has pagination in place but only returns a single page of results, and this doesn't match the semantics we want in Wagtail (where a single page of results should display "Page 1 of 1").
pull/10626/head
Matt Westcott 2023-07-07 16:39:26 +01:00 zatwierdzone przez Matt Westcott
rodzic 910490ae2f
commit 99a3febcad
1 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

@ -176,6 +176,10 @@ class BaseListingView(WagtailAdminTemplateMixin, BaseListView):
context["index_url"] = self.index_url
context["table"] = table
context["media"] = table.media
context["is_paginated"] = bool(self.paginate_by)
# On Django's BaseListView, a listing where pagination is applied, but the results
# only run to a single page, is considered is_paginated=False. Override this to
# always consider a listing to be paginated if pagination is applied. This ensures
# that we output "Page 1 of 1" as is standard in Wagtail.
context["is_paginated"] = context["page_obj"] is not None
return context