mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-18 17:13:00 +08:00
Add unrestricted document request view for head
This commit is contained in:
parent
c9e6928e8a
commit
0415d99968
3 changed files with 49 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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/<int:pk>/", DocumentRequestUpdateView.as_view()),
|
||||
]
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue