From c1c0098b7aa3041617927dadfe88343e575b965a Mon Sep 17 00:00:00 2001 From: Jordan Hyatt Date: Wed, 18 Sep 2024 17:47:40 -0400 Subject: [PATCH 1/2] implemented new paginate_table_by namespace that allows per_page to be set without ListView taking over EmptyPage error handling --- django_tables2/views.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/django_tables2/views.py b/django_tables2/views.py index 841bf901..6ad9d796 100644 --- a/django_tables2/views.py +++ b/django_tables2/views.py @@ -41,7 +41,7 @@ def get_table_pagination(self, table): paginate = {} # Obtains and set page size from get_paginate_by - paginate_by = self.get_paginate_by(table.data) + paginate_by = self.get_paginate_by(table.data) or self.get_paginate_table_by(table.data) if paginate_by is not None: paginate["per_page"] = paginate_by @@ -73,6 +73,18 @@ def get_paginate_by(self, table_data) -> Optional[int]: """ return getattr(self, "paginate_by", None) + def get_paginate_table_by(self, table_data) -> Optional[int]: + """ + Determines the number of items per page, or ``None`` for no pagination. + + Args: + table_data: The table's data. + + Returns: + Optional[int]: Items per page or ``None`` for no pagination. + """ + return getattr(self, "paginate_table_by", None) + class SingleTableMixin(TableMixinBase): """ From bc33faaeaf72eed7e5bac546accda1c5d9ee54b7 Mon Sep 17 00:00:00 2001 From: Jordan Hyatt Date: Wed, 18 Sep 2024 17:48:55 -0400 Subject: [PATCH 2/2] modified doc string --- django_tables2/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_tables2/views.py b/django_tables2/views.py index 6ad9d796..356f7b75 100644 --- a/django_tables2/views.py +++ b/django_tables2/views.py @@ -75,7 +75,7 @@ def get_paginate_by(self, table_data) -> Optional[int]: def get_paginate_table_by(self, table_data) -> Optional[int]: """ - Determines the number of items per page, or ``None`` for no pagination. + Alternate method for setting paginate_by that does not conflict with ListView Args: table_data: The table's data.