From d1955b7a87fcd126b3c0a6b33ec2e7df6495b3de Mon Sep 17 00:00:00 2001 From: Kunal Sharma Date: Thu, 28 Jan 2021 02:40:17 +0530 Subject: update paginated response in list infraction --- pydis_site/apps/api/viewsets/bot/infraction.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pydis_site/apps/api/viewsets') diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py index 2ccb35dd..851eae34 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -133,6 +133,21 @@ class InfractionViewSet( filter_fields = ('user__id', 'actor__id', 'active', 'hidden', 'type') search_fields = ('$reason',) frozen_fields = ('id', 'inserted_at', 'type', 'user', 'actor', 'hidden') + LimitOffsetPagination.default_limit = 100 + + def list(self, request: HttpRequest, *args, **kwargs) -> Response: + """ + DRF method for listing Infraction entries. + + Called by the Django Rest Framework in response to the corresponding HTTP request. + """ + queryset = self.filter_queryset(self.get_queryset()) + page = self.paginate_queryset(queryset) + if page: + serializer = self.get_serializer(page, many=True) + return Response(self.get_paginated_response(serializer.data).data.get('results')) + serializer = InfractionSerializer(queryset, many=True) + return Response(serializer.data) def partial_update(self, request: HttpRequest, *_args, **_kwargs) -> Response: """Method that handles the nuts and bolts of updating an Infraction.""" -- cgit v1.2.3