Skip to content

Commit

Permalink
feat(generic): allow to disabel pagination in table class
Browse files Browse the repository at this point in the history
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
  • Loading branch information
b1rger committed Nov 27, 2024
1 parent 624d74a commit 05f9ebf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 05f9ebf

Please sign in to comment.