Skip to content

Commit

Permalink
Implement list responses with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
snnbotchway committed Mar 13, 2023
1 parent 08b8eb2 commit 474c942
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions b2b/feedback/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Feedback app pagination."""
from rest_framework.pagination import PageNumberPagination


class ResponsePagination(PageNumberPagination):
"""Response pagination class."""

page_size = 1
16 changes: 15 additions & 1 deletion b2b/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework.viewsets import GenericViewSet

from .models import Client, Questionnaire, Response
from .pagination import ResponsePagination
from .permissions import (
IsClientRepresentative,
IsSalesManager,
Expand Down Expand Up @@ -92,13 +93,26 @@ def perform_create(self, serializer):

class ResponseViewSet(
CreateModelMixin,
ListModelMixin,
GenericViewSet,
):
"""The Response viewset."""

queryset = Response.objects.all()
serializer_class = ResponseSerializer
permission_classes = [IsClientRepresentative]
pagination_class = ResponsePagination

def get_queryset(self):
"""Filter responses with questionnaire id in url."""
return self.queryset.filter(
questionnaire_id=self.kwargs["questionnaire_pk"]
).order_by("id")

def get_permissions(self):
"""Return appropriate permissions."""
if self.request.method in SAFE_METHODS:
return [IsSalesManager()]
return [IsClientRepresentative()]

def get_serializer_context(self):
"""Pass user and questionnaire id to serializer for validation."""
Expand Down

0 comments on commit 474c942

Please sign in to comment.