DocManagerBackend/docmanager_backend/documents/views.py

69 lines
1.9 KiB
Python
Raw Permalink Normal View History

2024-11-23 23:02:52 +08:00
from rest_framework import generics
from .serializers import (
DocumentSerializer,
2024-11-24 02:20:18 +08:00
DocumentFileSerializer,
2024-11-23 23:02:52 +08:00
DocumentUploadSerializer,
DocumentDeleteSerializer,
2024-12-04 15:39:39 +08:00
DocumentUpdateSerializer
2024-11-23 23:02:52 +08:00
)
from rest_framework.permissions import IsAuthenticated
from rest_framework.pagination import PageNumberPagination
2024-12-04 15:39:39 +08:00
from accounts.permissions import IsStaff, IsHead
2024-11-24 02:20:18 +08:00
from .models import Document
2024-11-23 23:02:52 +08:00
2024-12-04 15:39:39 +08:00
class DocumentUpdateView(generics.UpdateAPIView):
"""
Used by staff to upload documents.
"""
http_method_names = ["patch"]
serializer_class = DocumentUpdateSerializer
queryset = Document.objects.all()
permission_classes = [IsAuthenticated, IsHead]
2024-11-23 23:02:52 +08:00
class DocumentUploadView(generics.CreateAPIView):
2024-11-24 02:20:18 +08:00
"""
Used by staff to upload documents.
"""
2024-11-23 23:02:52 +08:00
http_method_names = ["post"]
serializer_class = DocumentUploadSerializer
2024-11-24 02:20:18 +08:00
permission_classes = [IsAuthenticated, IsStaff]
2024-11-23 23:02:52 +08:00
class DocumentDeleteView(generics.DestroyAPIView):
2024-11-24 02:20:18 +08:00
"""
Used by staff to delete documents. Accepts the document id as a URL parameter
"""
2024-11-23 23:02:52 +08:00
http_method_names = ["delete"]
serializer_class = DocumentDeleteSerializer
queryset = Document.objects.all()
2024-11-24 02:20:18 +08:00
permission_classes = [IsAuthenticated, IsStaff]
2024-11-23 23:02:52 +08:00
class DocumentListView(generics.ListAPIView):
2024-11-24 02:20:18 +08:00
"""
Used by clients to view documents. Does not include actual download links to documents
"""
2024-11-23 23:02:52 +08:00
http_method_names = ["get"]
serializer_class = DocumentSerializer
2024-12-16 14:58:50 +08:00
queryset = Document.objects.all().order_by("-date_uploaded")
2024-11-23 23:02:52 +08:00
pagination_class = PageNumberPagination
2024-11-24 02:20:18 +08:00
permission_classes = [IsAuthenticated]
class DocumentStaffListView(generics.ListAPIView):
"""
Used by staff to view documents. Includes actual download links to documents
"""
http_method_names = ["get"]
serializer_class = DocumentFileSerializer
queryset = Document.objects.all()
pagination_class = PageNumberPagination
permission_classes = [IsAuthenticated, IsStaff]