Skip to content

Commit

Permalink
Add list MonthlyFeedback functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
snnbotchway committed Mar 14, 2023
1 parent f150e5d commit c2d35df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions b2b/feedback/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ class ResponsePagination(PageNumberPagination):
"""Response pagination class."""

page_size = 1


class MonthlyFeedbackPagination(PageNumberPagination):
"""Monthly feedback pagination."""

page_size = 10
23 changes: 21 additions & 2 deletions b2b/feedback/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Views for the feedback app."""
from django.contrib.auth import get_user_model
from rest_framework.mixins import (
CreateModelMixin,
DestroyModelMixin,
Expand All @@ -9,7 +10,7 @@
from rest_framework.viewsets import GenericViewSet

from .models import Client, MonthlyFeedback, Questionnaire, Response
from .pagination import ResponsePagination
from .pagination import MonthlyFeedbackPagination, ResponsePagination
from .permissions import (
IsClientRepresentative,
IsSalesManager,
Expand All @@ -23,6 +24,8 @@
ResponseSerializer,
)

User = get_user_model()


class ClientViewSet(
CreateModelMixin,
Expand Down Expand Up @@ -132,13 +135,29 @@ def perform_create(self, serializer):

class MonthlyFeedbackViewSet(
CreateModelMixin,
ListModelMixin,
GenericViewSet,
):
"""The monthly feedback view set."""

queryset = MonthlyFeedback.objects.all()
serializer_class = MonthlyFeedbackSerializer
permission_classes = [IsClientRepresentative]
pagination_class = MonthlyFeedbackPagination

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

def get_queryset(self):
"""Filter feedback for the current user."""
current_user_clients = Client.objects.select_related(
"client_rep", "sales_manager"
).filter(sales_manager=self.request.user)
return self.queryset.filter(
client_rep__in=[client.client_rep for client in current_user_clients]
).order_by("-month")

def perform_create(self, serializer):
"""Assign current user as the client rep."""
Expand Down

0 comments on commit c2d35df

Please sign in to comment.