Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paging limit of 1000 to several endpoints #1278

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/apps/decisions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
DecisionSerializer,
DecisionTypeSerializer,
)
from apps.main.pagination import LimitedOffsetPaginator
from apps.users.permissions import CanPerformTask, rest_permission_classes_for_top
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema
Expand All @@ -24,6 +25,7 @@ class DecisionViewSet(GenericViewSet, CreateModelMixin, ListModelMixin):
serializer_class = DecisionSerializer
queryset = Decision.objects.all()
filter_backends = [DjangoFilterBackend]
paginator_class = LimitedOffsetPaginator
filterset_fields = {
"case": [
"exact",
Expand Down
6 changes: 5 additions & 1 deletion app/apps/main/pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict

from rest_framework.exceptions import NotFound
from rest_framework.pagination import PageNumberPagination
from rest_framework.pagination import LimitOffsetPagination, PageNumberPagination
from rest_framework.response import Response


Expand Down Expand Up @@ -31,3 +31,7 @@ def get_paginated_response(self, data):
]
)
)


class LimitedOffsetPaginator(LimitOffsetPagination):
max_limit = 1000
2 changes: 2 additions & 0 deletions app/apps/summons/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from apps.main.pagination import LimitedOffsetPaginator
from apps.summons.models import Summon, SummonedPerson, SummonType
from apps.summons.serializers import (
SummonedPersonAnonomizedSerializer,
Expand All @@ -21,6 +22,7 @@ class SummonViewSet(GenericViewSet, CreateModelMixin, ListModelMixin):
queryset = Summon.objects.all()
filter_backends = [DjangoFilterBackend]
filterset_fields = ["case"]
pagination_class = LimitedOffsetPaginator

def get_permissions(self):
if self.request.method not in SAFE_METHODS:
Expand Down
2 changes: 2 additions & 0 deletions app/apps/visits/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from apps.main.pagination import LimitedOffsetPaginator
from apps.users.permissions import rest_permission_classes_for_top
from rest_framework.mixins import CreateModelMixin, ListModelMixin
from rest_framework.viewsets import GenericViewSet
Expand All @@ -10,3 +11,4 @@ class VisitViewSet(GenericViewSet, CreateModelMixin, ListModelMixin):
permission_classes = rest_permission_classes_for_top()
serializer_class = VisitSerializer
queryset = Visit.objects.all()
pagination_class = LimitedOffsetPaginator
Loading