Skip to content

Commit

Permalink
Merge pull request #1278 from Amsterdam/fix/128773-add-paging-limits
Browse files Browse the repository at this point in the history
Add paging limit of 1000 to several endpoints
  • Loading branch information
NvdLaan authored Oct 21, 2024
2 parents e45c879 + 1c070f9 commit ca189e2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
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

0 comments on commit ca189e2

Please sign in to comment.