From 98d5a18f525fe60f9d4365a44181c65f7ab33530 Mon Sep 17 00:00:00 2001 From: Nino Date: Mon, 21 Oct 2024 14:36:17 +0200 Subject: [PATCH 1/2] Add paging limit of 1000 to several endpoints --- app/apps/decisions/views.py | 2 ++ app/apps/main/pagination.py | 6 +++++- app/apps/summons/views.py | 2 ++ app/apps/visits/views.py | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/apps/decisions/views.py b/app/apps/decisions/views.py index 19c32a833..5cda63c3a 100644 --- a/app/apps/decisions/views.py +++ b/app/apps/decisions/views.py @@ -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 @@ -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", diff --git a/app/apps/main/pagination.py b/app/apps/main/pagination.py index 958d56f83..c08ced36e 100644 --- a/app/apps/main/pagination.py +++ b/app/apps/main/pagination.py @@ -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 @@ -31,3 +31,7 @@ def get_paginated_response(self, data): ] ) ) + + +class LimitedOffsetPaginator(LimitOffsetPagination): + max_limit = 1000 diff --git a/app/apps/summons/views.py b/app/apps/summons/views.py index e7095ebd4..7d915233c 100644 --- a/app/apps/summons/views.py +++ b/app/apps/summons/views.py @@ -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, @@ -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: diff --git a/app/apps/visits/views.py b/app/apps/visits/views.py index ff0063004..255127f76 100644 --- a/app/apps/visits/views.py +++ b/app/apps/visits/views.py @@ -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 @@ -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 From 1c070f96fca304cf329a221e0dbdb3fbed1a2941 Mon Sep 17 00:00:00 2001 From: Nino Date: Mon, 21 Oct 2024 14:38:49 +0200 Subject: [PATCH 2/2] change format --- app/apps/decisions/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/apps/decisions/views.py b/app/apps/decisions/views.py index 5cda63c3a..703594e8f 100644 --- a/app/apps/decisions/views.py +++ b/app/apps/decisions/views.py @@ -25,7 +25,7 @@ class DecisionViewSet(GenericViewSet, CreateModelMixin, ListModelMixin): serializer_class = DecisionSerializer queryset = Decision.objects.all() filter_backends = [DjangoFilterBackend] - paginator_class = (LimitedOffsetPaginator,) + paginator_class = LimitedOffsetPaginator filterset_fields = { "case": [ "exact",