diff --git a/docmanager_backend/document_requests/serializers.py b/docmanager_backend/document_requests/serializers.py index 3ecd738..62f4748 100644 --- a/docmanager_backend/document_requests/serializers.py +++ b/docmanager_backend/document_requests/serializers.py @@ -113,6 +113,40 @@ class DocumentRequestSerializer(serializers.ModelSerializer): return serializer_class(obj.documents, many=True).data +class FullDocumentRequestSerializer(serializers.ModelSerializer): + documents = DocumentRequestUnitWithFileSerializer() + requester = serializers.SlugRelatedField( + many=False, slug_field="email", queryset=CustomUser.objects.all(), required=False + ) + purpose = serializers.CharField(max_length=512) + date_requested = serializers.DateTimeField( + format="%m-%d-%Y %I:%M %p", read_only=True + ) + + class Meta: + model = DocumentRequest + fields = [ + "id", + "requester", + "college", + "type", + "purpose", + "date_requested", + "documents", + "status", + ] + read_only_fields = [ + "id", + "requester", + "college", + "type", + "purpose", + "date_requested", + "documents", + "status", + ] + + class DocumentRequestUpdateSerializer(serializers.ModelSerializer): status = serializers.ChoiceField( choices=DocumentRequest.STATUS_CHOICES, required=True diff --git a/docmanager_backend/document_requests/urls.py b/docmanager_backend/document_requests/urls.py index 15d71f3..75c922d 100644 --- a/docmanager_backend/document_requests/urls.py +++ b/docmanager_backend/document_requests/urls.py @@ -3,10 +3,12 @@ from .views import ( DocumentRequestCreateView, DocumentRequestListView, DocumentRequestUpdateView, + DocumentRequestFullListView ) urlpatterns = [ path("create/", DocumentRequestCreateView.as_view()), path("list/", DocumentRequestListView.as_view()), + path("list/head/", DocumentRequestFullListView.as_view()), path("update//", DocumentRequestUpdateView.as_view()), ] diff --git a/docmanager_backend/document_requests/views.py b/docmanager_backend/document_requests/views.py index 9c496ca..4272030 100644 --- a/docmanager_backend/document_requests/views.py +++ b/docmanager_backend/document_requests/views.py @@ -42,6 +42,19 @@ class DocumentRequestListView(generics.ListAPIView): return queryset +class DocumentRequestFullListView(generics.ListAPIView): + """ + Returns document requests. Always returns the link to download the document. + Head is able to view all document requests here. Staff and clients have no access + """ + + http_method_names = ["get"] + serializer_class = DocumentRequestSerializer + pagination_class = PageNumberPagination + permission_classes = [IsAuthenticated, IsHead] + queryset = DocumentRequest.objects.all() + + class DocumentRequestUpdateView(generics.UpdateAPIView): """ Used by head approve or deny document requests.