Skip to content

Commit

Permalink
Improve PageSizeSelectMixin ( transfer from RADIS)
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Jan 5, 2024
1 parent 81ef068 commit be8791a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@

## Maybe

- Replace with_type_hint by Protocols
-- RADIS currently uses Protocols for type hints but ADIT with_type_hint for mixins
-- Protocols would work instead for the with_type_hint implementation in mypy
-- Protocols are also the official way to type hint mixins
- New batch transfer
-- Create new batch transfer job and allow to add tasks
-- Add tasks manually or using a Excel file
Expand Down
19 changes: 13 additions & 6 deletions adit/core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,22 @@ class PageSizeSelectMixin(with_type_hint(ListView)):
which is used by this mixin for the page size.
"""

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
# Make the initial paginate_by attribute the default page size if set
if not hasattr(self, "paginate_by") or self.paginate_by is None:
self.paginate_by = 50

try:
per_page = int(self.request.GET.get("per_page", 50))
per_page = int(request.GET.get("per_page", self.paginate_by))
except ValueError:
per_page = 50
per_page = self.paginate_by

per_page = min(per_page, 1000)
self.paginate_by = per_page # Used by django_tables2
per_page = min(per_page, 100)
self.paginate_by = per_page # used by MultipleObjectMixin (and also django_tables2)

return super().get(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_size_select"] = PageSizeSelectForm(self.request.GET, [50, 100, 250, 500])
return context

0 comments on commit be8791a

Please sign in to comment.