fix: Swagger schema fix, comments add
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
||||
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||
|
||||
from core.apps.contracts.models import ContractAttachedFileModel
|
||||
from core.apps.contracts.serializers.attached_files import (
|
||||
@@ -13,8 +13,11 @@ from core.apps.contracts.serializers.attached_files import (
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["ContractAttachedFile"])
|
||||
class ContractAttachedFileView(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @view-set | ALL - /contract-attached-files
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Attached Files"])
|
||||
class ContractAttachedFileViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = ContractAttachedFileModel.objects.all()
|
||||
serializer_class = ListContractAttachedFileSerializer
|
||||
permission_classes = [AllowAny]
|
||||
@@ -26,7 +29,7 @@ class ContractAttachedFileView(BaseViewSetMixin, ModelViewSet):
|
||||
"update": [IsAdminUser],
|
||||
"destroy": [IsAdminUser],
|
||||
}
|
||||
action_serializer_class = {
|
||||
action_serializer_class = { # type: ignore
|
||||
"list": ListContractAttachedFileSerializer,
|
||||
"retrieve": RetrieveContractAttachedFileSerializer,
|
||||
"create": CreateContractAttachedFileSerializer,
|
||||
|
||||
@@ -4,11 +4,11 @@ from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser, IsAuthenticated # type: ignore
|
||||
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||
from rest_framework.views import APIView # type: ignore
|
||||
from rest_framework.generics import GenericAPIView # type: ignore
|
||||
from core.utils.views import BaseApiViewMixin
|
||||
|
||||
from rest_framework.request import HttpRequest # type: ignore
|
||||
from rest_framework.response import Response # type: ignore
|
||||
from rest_framework.decorators import action # type: ignore
|
||||
from rest_framework.generics import get_object_or_404 # type: ignore
|
||||
from rest_framework import status # type: ignore
|
||||
|
||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||
@@ -29,8 +29,11 @@ from core.apps.contracts.serializers import (
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["Contract"])
|
||||
class ContractView(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @view-set | ALL - /contracts
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contracts"])
|
||||
class ContractViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = ContractModel.objects.all()
|
||||
serializer_class = ListContractSerializer
|
||||
permission_classes = [AllowAny]
|
||||
@@ -60,83 +63,103 @@ class ContractView(BaseViewSetMixin, ModelViewSet):
|
||||
return super().create(request, *args, **kwargs) # type: ignore
|
||||
|
||||
|
||||
class ContractRelationsViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @api-view | GET - /contracts/{id}/owners
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Owners"])
|
||||
class ContractOwnerApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
queryset = ContractModel.objects.all()
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
action_permission_classes = {
|
||||
"list_file": [AllowAny],
|
||||
"list_owner": [AllowAny],
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
action_serializer_class = { # type: ignore
|
||||
"list_file": ListContractAttachedFileSerializer,
|
||||
"list_owner": RetrieveContractOwnerSerializer,
|
||||
method_serializer_class = {
|
||||
"get": RetrieveContractOwnerSerializer,
|
||||
}
|
||||
|
||||
@extend_schema(
|
||||
summary="Get List Of Owners",
|
||||
description="Get list of owners"
|
||||
)
|
||||
def get(self, *args: object, **kwargs: object) -> Response:
|
||||
contract = self.get_object()
|
||||
owners = ContractOwnerModel.objects.filter(contract=contract)
|
||||
ser = self.get_serializer(instance=owners, many=True)
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
|
||||
###################################################################################
|
||||
# @api-view | GET - /contracts/{id}/files
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Attached Files"])
|
||||
class ContractAttachedFileApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
queryset = ContractModel.objects.all()
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {
|
||||
"get": ListContractAttachedFileSerializer,
|
||||
}
|
||||
|
||||
@extend_schema(
|
||||
summary="Get List Of Files",
|
||||
description="Get List Of Files"
|
||||
)
|
||||
@action(url_path="files", detail=True, methods=["GET"])
|
||||
def list_file(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
contract = get_object_or_404(ContractModel, pk=pk)
|
||||
def get(self, *args: object, **kwargs: object) -> Response:
|
||||
contract = self.get_object()
|
||||
files = ContractAttachedFileModel.objects.filter(contract=contract)
|
||||
ser = self.get_serializer(instance=files, many=True) # type: ignore
|
||||
ser = self.get_serializer(instance=files, many=True)
|
||||
return Response(data=ser.data, status=status.HTTP_200_OK)
|
||||
|
||||
@extend_schema(
|
||||
summary="Get List Of Owners",
|
||||
description="Get list of owners"
|
||||
)
|
||||
@action(url_path="owners", detail=True, methods=["GET"])
|
||||
def list_owner(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
contract = get_object_or_404(ContractModel, pk=pk)
|
||||
owners = ContractOwnerModel.objects.filter(contract=contract)
|
||||
ser = self.get_serializer(instance=owners, many=True) # type: ignore
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ContractDetailView(APIView):
|
||||
###################################################################################
|
||||
# @api-view | GET - /contract-owners/{id}/contract
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Owners"])
|
||||
class ContractDetailApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
queryset = ContractOwnerModel.objects.all()
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {
|
||||
"get": RetrieveContractSerializer
|
||||
}
|
||||
|
||||
@extend_schema(
|
||||
summary="Uploads a file for contract attached files",
|
||||
description="Creates a file for contract attached files.",
|
||||
)
|
||||
def get(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
owner_id: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
contract = ContractModel.objects.filter(owners__id=owner_id)[0]
|
||||
ser = RetrieveContractSerializer(instance=contract)
|
||||
def get(self, request: HttpRequest, pk: uuid.UUID, *args: object, **kwargs: object) -> Response:
|
||||
contract = ContractModel.objects.filter(owners__id=pk)[0]
|
||||
ser = self.get_serializer(instance=contract) # type: ignore
|
||||
return Response(ser.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ListFolderContractsView(APIView):
|
||||
permission_classes = [IsAdminUser]
|
||||
###################################################################################
|
||||
# @api-view | GET - /folders/{id}/contracts
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contracts"])
|
||||
class ListFolderContractsApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
permission_classes = [AllowAny]
|
||||
queryset = ContractOwnerModel.objects.all()
|
||||
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {
|
||||
"get": ListContractSerializer
|
||||
}
|
||||
|
||||
def get(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
@extend_schema(
|
||||
summary="Get Contracts related to folders",
|
||||
description="Get Contracts related to folders",
|
||||
)
|
||||
def get(self, request: HttpRequest, pk: uuid.UUID, *args: object, **kwargs: object) -> Response:
|
||||
contracts = ContractModel.objects.filter(folders__id=pk)
|
||||
ser = ListContractSerializer(instance=contracts, many=True)
|
||||
ser = self.get_serializer(instance=contracts, many=True) # type: ignore
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
||||
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||
|
||||
from core.apps.contracts.models import ContractFileContentModel
|
||||
from core.apps.contracts.serializers.file_contents import (
|
||||
@@ -13,8 +13,11 @@ from core.apps.contracts.serializers.file_contents import (
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["ContractFileContent"])
|
||||
class ContractFileContentView(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @view-set | ALL - /contract-file-contents
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract File Contents"])
|
||||
class ContractFileContentViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = ContractFileContentModel.objects.all()
|
||||
serializer_class = ListContractFileContentSerializer
|
||||
permission_classes = [AllowAny]
|
||||
@@ -26,7 +29,7 @@ class ContractFileContentView(BaseViewSetMixin, ModelViewSet):
|
||||
"update": [IsAdminUser],
|
||||
"destroy": [IsAdminUser],
|
||||
}
|
||||
action_serializer_class = {
|
||||
action_serializer_class = { # type: ignore
|
||||
"list": ListContractFileContentSerializer,
|
||||
"retrieve": RetrieveContractFileContentSerializer,
|
||||
"create": CreateContractFileContentSerializer,
|
||||
|
||||
@@ -3,18 +3,18 @@ from typing import cast
|
||||
|
||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||
from django.utils.translation import gettext as _
|
||||
from drf_spectacular.utils import extend_schema, OpenApiResponse
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.exceptions import PermissionDenied # type: ignore
|
||||
from rest_framework.decorators import action # type: ignore
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
||||
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||
from rest_framework.request import HttpRequest # type: ignore
|
||||
from rest_framework.response import Response # type: ignore
|
||||
from rest_framework import status # type: ignore
|
||||
from rest_framework.views import APIView # type: ignore
|
||||
from rest_framework.generics import GenericAPIView # type: ignore
|
||||
from rest_framework.parsers import MultiPartParser, FormParser # type: ignore
|
||||
from rest_framework.generics import get_object_or_404 # type: ignore
|
||||
|
||||
from core.utils.views import BaseApiViewMixin
|
||||
from core.apps.contracts.models import (
|
||||
ContractOwnerModel,
|
||||
ContractAttachedFileModel,
|
||||
@@ -26,14 +26,15 @@ from core.apps.contracts.serializers import (
|
||||
UpdateContractOwnerSerializer,
|
||||
DestroyContractOwnerSerializer,
|
||||
|
||||
RetrieveContractAttachedFileSerializer,
|
||||
CreateContractAttachedFileSerializer,
|
||||
CreateContractFileContentFromOwnerSerializer,
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["ContractOwner"])
|
||||
class ContractOwnerView(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @view-set | ALL - /contract-owners
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Owners"])
|
||||
class ContractOwnerViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = ContractOwnerModel.objects.all()
|
||||
serializer_class = ListContractOwnerSerializer
|
||||
permission_classes = [AllowAny]
|
||||
@@ -54,63 +55,20 @@ class ContractOwnerView(BaseViewSetMixin, ModelViewSet):
|
||||
}
|
||||
|
||||
|
||||
# class ContractOwnerFileViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
# queryset = ContractOwnerModel.objects.all()
|
||||
# serializer_class = RetrieveContractAttachedFileSerializer
|
||||
# permission_classes = [AllowAny]
|
||||
|
||||
# action_serializer_class = { # type: ignore
|
||||
# "list_file": RetrieveContractAttachedFileSerializer,
|
||||
# "create_file": CreateContractAttachedFileSerializer,
|
||||
# }
|
||||
|
||||
# @extend_schema(
|
||||
# summary="Contract Files Related to Owner",
|
||||
# description="Contract Files Related to Owner",
|
||||
# )
|
||||
# @action(url_path="files", methods=["GET"], detail=True)
|
||||
# def list_file(
|
||||
# self,
|
||||
# request: HttpRequest,
|
||||
# *args: object,
|
||||
# **kwargs: object,
|
||||
# ) -> Response:
|
||||
# owner = cast(ContractOwnerModel, self.get_object())
|
||||
# files = ContractAttachedFileModel.objects.filter(
|
||||
# contract__owners=owner, contents__owner=owner
|
||||
# ).select_related("contents")
|
||||
# serializer = self.get_serializer(instance=files, many=True)
|
||||
# return Response(serializer.data, status.HTTP_200_OK)
|
||||
|
||||
# @extend_schema(
|
||||
# summary="Create Contract Files Related to Owner",
|
||||
# description="Create Contract Files Related to Owner"
|
||||
# )
|
||||
# @action(url_path="files", methods=["GET"], detail=True)
|
||||
# def create_file(
|
||||
# self,
|
||||
# request: HttpRequest,
|
||||
# *args: object,
|
||||
# **kwargs: object,
|
||||
# ) -> Response:
|
||||
# owner = cast(
|
||||
# ContractOwnerModel,
|
||||
# self.get_queryset().select_related("contract")
|
||||
# )
|
||||
# if not owner.contract.allow_add_files:
|
||||
# raise PermissionDenied(_("Attaching new files was restricted for this contract."))
|
||||
# ser = self.get_serializer(data=request.data)
|
||||
# ser.is_valid(raise_exception=True)
|
||||
# ser.save() # type: ignore
|
||||
# return Response(ser.data, status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ContractAttachedFileDeleteView(APIView):
|
||||
###################################################################################
|
||||
# @api-view | DELETE - /contract-owners/{owner_id}/files/{file_id}
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Files"])
|
||||
class ContractOwnerAttachedFileApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
permission_classes = [AllowAny]
|
||||
queryset = ContractOwnerModel.objects.all()
|
||||
|
||||
method_permission_classes = {
|
||||
"delete": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {}
|
||||
|
||||
@extend_schema(
|
||||
# request=ContractFileDeleteRequestSerializer,
|
||||
responses={204: OpenApiResponse(description="File successfully deleted.")},
|
||||
summary="Delete a file from contract",
|
||||
description="Deletes a contract-attached file if contract allows file deletion.",
|
||||
)
|
||||
@@ -127,25 +85,30 @@ class ContractAttachedFileDeleteView(APIView):
|
||||
)
|
||||
if not owner.contract.allow_delete_files:
|
||||
raise PermissionDenied(_("Deleting attached files was restricted for this contract"))
|
||||
|
||||
file = get_object_or_404(
|
||||
ContractAttachedFileModel.objects.all().select_related("contract"),
|
||||
pk=file_id
|
||||
ContractAttachedFileModel.objects.all().select_related("contract"), pk=file_id
|
||||
)
|
||||
if owner.contract.pk != file.contract.pk:
|
||||
raise PermissionDenied(_("Contract have no such file attached"))
|
||||
file.delete()
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
class UploadFileContentView(APIView):
|
||||
|
||||
###################################################################################
|
||||
# @api-view | POST - /contract-owners/{owner_id}/files/{file_id}/upload
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract File contents"])
|
||||
class UploadFileContentApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
permission_classes = [AllowAny]
|
||||
parser_classes = [MultiPartParser, FormParser] # type: ignore
|
||||
|
||||
method_permission_classes = {"post": [AllowAny]}
|
||||
method_serializer_class = {"post": CreateContractFileContentFromOwnerSerializer}
|
||||
|
||||
@extend_schema(
|
||||
summary="Uploads a file for contract attached files",
|
||||
description="Creates a file for contract attached files.",
|
||||
request=CreateContractFileContentFromOwnerSerializer,
|
||||
responses={201: CreateContractFileContentFromOwnerSerializer},
|
||||
)
|
||||
def post(
|
||||
self,
|
||||
@@ -155,13 +118,11 @@ class UploadFileContentView(APIView):
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
serializer = CreateContractFileContentFromOwnerSerializer(
|
||||
data=request.data, # type: ignore
|
||||
context={
|
||||
"file_id": file_id,
|
||||
"contract_owner_id": owner_id,
|
||||
}
|
||||
serializer_context = dict(file_id=file_id, contract_owner_id=owner_id)
|
||||
serializer = cast(
|
||||
CreateContractFileContentFromOwnerSerializer,
|
||||
self.get_serializer(data=request.data, context=serializer_context) # type: ignore
|
||||
)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save() # type: ignore
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
Reference in New Issue
Block a user