Skip to content

Commit

Permalink
Merge 83b5f8e into 1c5df70
Browse files Browse the repository at this point in the history
  • Loading branch information
kunal097 committed Jan 27, 2021
2 parents 1c5df70 + 83b5f8e commit 6383d85
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pydis_site/apps/api/viewsets/bot/infraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ListModelMixin,
RetrieveModelMixin
)
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand Down Expand Up @@ -133,10 +134,27 @@ class InfractionViewSet(

serializer_class = InfractionSerializer
queryset = Infraction.objects.all()
pagination_class = LimitOffsetPagination
filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
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)
result = self.get_paginated_response(serializer.data)
return Response(result.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."""
Expand Down

0 comments on commit 6383d85

Please sign in to comment.