Add unrestricted document request view for head

This commit is contained in:
Keannu Bernasol 2024-11-25 02:35:59 +08:00
parent c9e6928e8a
commit 0415d99968
3 changed files with 49 additions and 0 deletions

View file

@ -113,6 +113,40 @@ class DocumentRequestSerializer(serializers.ModelSerializer):
return serializer_class(obj.documents, many=True).data 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): class DocumentRequestUpdateSerializer(serializers.ModelSerializer):
status = serializers.ChoiceField( status = serializers.ChoiceField(
choices=DocumentRequest.STATUS_CHOICES, required=True choices=DocumentRequest.STATUS_CHOICES, required=True

View file

@ -3,10 +3,12 @@ from .views import (
DocumentRequestCreateView, DocumentRequestCreateView,
DocumentRequestListView, DocumentRequestListView,
DocumentRequestUpdateView, DocumentRequestUpdateView,
DocumentRequestFullListView
) )
urlpatterns = [ urlpatterns = [
path("create/", DocumentRequestCreateView.as_view()), path("create/", DocumentRequestCreateView.as_view()),
path("list/", DocumentRequestListView.as_view()), path("list/", DocumentRequestListView.as_view()),
path("list/head/", DocumentRequestFullListView.as_view()),
path("update/<int:pk>/", DocumentRequestUpdateView.as_view()), path("update/<int:pk>/", DocumentRequestUpdateView.as_view()),
] ]

View file

@ -42,6 +42,19 @@ class DocumentRequestListView(generics.ListAPIView):
return queryset 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): class DocumentRequestUpdateView(generics.UpdateAPIView):
""" """
Used by head approve or deny document requests. Used by head approve or deny document requests.