ticket.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from rest_framework import generics, permissions
  2. from rest_framework.exceptions import NotFound
  3. from tickets.models import Ticket
  4. from tickets.api.serializers import TicketDetailSerializer, TicketSerializer, TicketStatusSerializer
  5. from tickets.api.permissions import UserTicketAccessPermission, UserTicketStatusAccessPermission
  6. class TicketDetailAPIView(generics.RetrieveUpdateDestroyAPIView):
  7. queryset = Ticket.objects.all()
  8. serializer_class = TicketDetailSerializer
  9. permission_classes = [permissions.IsAuthenticated & UserTicketAccessPermission]
  10. class TicketCreateAPIView(generics.CreateAPIView):
  11. queryset = Ticket.objects.all()
  12. serializer_class = TicketSerializer
  13. permission_classes = [permissions.IsAuthenticated & UserTicketAccessPermission]
  14. def perform_create(self, serializer):
  15. if serializer.is_valid():
  16. serializer.save(created_by=self.request.user)
  17. class TicketStatusAPIView(generics.RetrieveUpdateAPIView):
  18. queryset = Ticket.objects.all()
  19. serializer_class = TicketStatusSerializer
  20. permission_classes = [permissions.IsAuthenticated & UserTicketStatusAccessPermission]