mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-08-21 12:40:36 +02:00
Implement My Tickets view in public helpdesk
Note: This is a breaking change as it forces pagination on the API endoints. This should have been done from the start as the API without pagination is useless when there are large numbers of tickets.
This commit is contained in:
@@ -1,10 +1,29 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from helpdesk.models import FollowUp, FollowUpAttachment, Ticket
|
||||
from helpdesk.serializers import FollowUpAttachmentSerializer, FollowUpSerializer, TicketSerializer, UserSerializer
|
||||
from helpdesk.serializers import FollowUpAttachmentSerializer, FollowUpSerializer, TicketSerializer, UserSerializer, PublicTicketListingSerializer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.mixins import CreateModelMixin
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
|
||||
class ConservativePagination(PageNumberPagination):
|
||||
page_size = 25
|
||||
page_size_query_param = 'page_size'
|
||||
|
||||
|
||||
class UserTicketViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
A list of all the tickets submitted by the current user
|
||||
|
||||
The view is paginated by default
|
||||
"""
|
||||
serializer_class = PublicTicketListingSerializer
|
||||
pagination_class = ConservativePagination
|
||||
|
||||
def get_queryset(self):
|
||||
return Ticket.objects.filter(submitter_email=self.request.user.email).order_by('-created')
|
||||
|
||||
|
||||
class TicketViewSet(viewsets.ModelViewSet):
|
||||
@@ -13,6 +32,7 @@ class TicketViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
queryset = Ticket.objects.all()
|
||||
serializer_class = TicketSerializer
|
||||
pagination_class = ConservativePagination
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
def get_queryset(self):
|
||||
@@ -30,12 +50,14 @@ class TicketViewSet(viewsets.ModelViewSet):
|
||||
class FollowUpViewSet(viewsets.ModelViewSet):
|
||||
queryset = FollowUp.objects.all()
|
||||
serializer_class = FollowUpSerializer
|
||||
pagination_class = ConservativePagination
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
|
||||
class FollowUpAttachmentViewSet(viewsets.ModelViewSet):
|
||||
queryset = FollowUpAttachment.objects.all()
|
||||
serializer_class = FollowUpAttachmentSerializer
|
||||
pagination_class = ConservativePagination
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user