From bd90a7742ede2df28af362a7f045f9e7fb4c7564 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Wed, 27 Nov 2024 09:17:25 +0100 Subject: [PATCH] feat(generic): allow to disable pagination in table class Instead of overriding the `get_paginate_by` method of the TableMixinBase, we now override the `get_table_pagination` method. This allows to also set the `table_pagination` setting in the table itself, therefore providing the means to disable the pagination alltogether. Closes: #1444 --- apis_core/generic/views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apis_core/generic/views.py b/apis_core/generic/views.py index 18e16d6c4..852d6cf54 100644 --- a/apis_core/generic/views.py +++ b/apis_core/generic/views.py @@ -1,6 +1,5 @@ from collections import namedtuple from copy import copy -from typing import Optional from dal import autocomplete from django import forms, http @@ -204,12 +203,14 @@ def get_queryset(self): queryset = first_member_match(queryset_methods) or (lambda x: x) return self.filter_queryset(queryset(self.model.objects.all())) - def get_paginate_by(self, table_data) -> Optional[int]: + def get_table_pagination(self, table): """ - Override `get_paginate_by` from the tables2 TableMixinBase, - so we can set the paginate_by value as attribute of the table. + Override `get_table_pagination` from the tables2 TableMixinBase, + so we can set the paginate_by and the table_pagination value as attribute of the table. """ - return getattr(self.get_table_class(), "paginate_by", None) + self.paginate_by = getattr(table, "paginate_by", None) + self.table_pagination = getattr(table, "table_pagination", None) + return super().get_table_pagination(table) class Detail(GenericModelMixin, PermissionRequiredMixin, DetailView):