fix bug
This commit is contained in:
@@ -128,6 +128,3 @@ class CreateQuickevaluationSerializer(serializers.ModelSerializer):
|
|||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
|
||||||
class ArchiveQuickevaluationSerializer(serializers.Serializer):
|
|
||||||
id = serializers.IntegerField(required=True)
|
|
||||||
is_archive = serializers.BooleanField(required=True)
|
|
||||||
@@ -30,8 +30,8 @@ from .views import (
|
|||||||
TechPassportAPIView,
|
TechPassportAPIView,
|
||||||
EvaluationStatusChange,
|
EvaluationStatusChange,
|
||||||
CertificateView,
|
CertificateView,
|
||||||
ArchiveQuickEvaluationView,
|
|
||||||
ArchiveEvaluationrequestView, GetArchivedEvaluationListAPIView, ArchivedEvaluation,
|
ArchiveEvaluationrequestView, GetArchivedEvaluationListAPIView, ArchivedEvaluation,
|
||||||
|
GetArchivedQuickevaluationListAPIView, ChangeQuickevaluationAPIView,
|
||||||
)
|
)
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
@@ -78,7 +78,9 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
path("evaluation-request/<int:pk>/change-status/", EvaluationStatusChange.as_view(),
|
path("evaluation-request/<int:pk>/change-status/", EvaluationStatusChange.as_view(),
|
||||||
name="evaluation-change-status"),
|
name="evaluation-change-status"),
|
||||||
path("archive/quick-evaluation/", ArchiveQuickEvaluationView.as_view(), name="quick-evaluation-archive"),
|
path("archive/quick-evaluation/", GetArchivedQuickevaluationListAPIView.as_view(), name="get-quick-evaluation-archive"),
|
||||||
|
path("archive/quick-evaluation/<int:pk>", ChangeQuickevaluationAPIView.as_view(), name="change-quick-evaluation-archive"),
|
||||||
|
|
||||||
path("archive/evaluation-request/", ArchiveEvaluationrequestView.as_view(), name="evaluation-request-archive"),
|
path("archive/evaluation-request/", ArchiveEvaluationrequestView.as_view(), name="evaluation-request-archive"),
|
||||||
|
|
||||||
path("archived-evaluvation/", GetArchivedEvaluationListAPIView.as_view(),
|
path("archived-evaluvation/", GetArchivedEvaluationListAPIView.as_view(),
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from django_core.mixins import BaseViewSetMixin
|
from django_core.mixins import BaseViewSetMixin
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from drf_spectacular.utils import extend_schema, OpenApiResponse
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from rest_framework import status
|
||||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||||
|
from rest_framework.generics import ListAPIView
|
||||||
from rest_framework.parsers import FormParser, MultiPartParser
|
from rest_framework.parsers import FormParser, MultiPartParser
|
||||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||||
from rest_framework.viewsets import ModelViewSet
|
|
||||||
from rest_framework.generics import GenericAPIView
|
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework.views import APIView
|
||||||
from django.shortcuts import get_object_or_404
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from core.apps.evaluation.filters.quick import QuickevaluationFilter
|
from core.apps.evaluation.filters.quick import QuickevaluationFilter
|
||||||
from core.apps.evaluation.models import QuickEvaluationModel
|
from core.apps.evaluation.models import QuickEvaluationModel
|
||||||
@@ -16,7 +17,6 @@ from core.apps.evaluation.serializers.quick import (
|
|||||||
CreateQuickevaluationSerializer,
|
CreateQuickevaluationSerializer,
|
||||||
ListQuickevaluationSerializer,
|
ListQuickevaluationSerializer,
|
||||||
RetrieveQuickevaluationSerializer,
|
RetrieveQuickevaluationSerializer,
|
||||||
ArchiveQuickevaluationSerializer,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -56,75 +56,27 @@ class QuickEvaluationView(BaseViewSetMixin, ModelViewSet):
|
|||||||
"create": CreateQuickevaluationSerializer,
|
"create": CreateQuickevaluationSerializer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["QuickEvaluation"])
|
@extend_schema(tags=["QuickEvaluation"])
|
||||||
class ArchiveQuickEvaluationView(GenericAPIView):
|
class ChangeQuickevaluationAPIView(APIView):
|
||||||
|
|
||||||
|
def post(self, request, pk):
|
||||||
|
instance = get_object_or_404(QuickEvaluationModel, pk=pk)
|
||||||
|
|
||||||
|
is_archived = request.data.get("is_archived")
|
||||||
|
if is_archived is None:
|
||||||
|
return Response(
|
||||||
|
{"error": "Поле 'is_archived' обязательно"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST
|
||||||
|
)
|
||||||
|
instance.is_archived = is_archived
|
||||||
|
instance.save()
|
||||||
|
return Response({"success": True}, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
@extend_schema(tags=["QuickEvaluation"])
|
||||||
|
class GetArchivedQuickevaluationListAPIView(ListAPIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_queryset(self):
|
||||||
if self.request.method == "GET":
|
return QuickEvaluationModel.objects.filter(is_archived=True)
|
||||||
return ListQuickevaluationSerializer
|
|
||||||
return ArchiveQuickevaluationSerializer
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["QuickEvaluation"],
|
|
||||||
summary="Get archived quick evaluations list",
|
|
||||||
description="""
|
|
||||||
Returns only archived quick evaluations.
|
|
||||||
|
|
||||||
This endpoint works like quick-evaluation/,
|
|
||||||
but only records with is_archive=True are returned.
|
|
||||||
""",
|
|
||||||
responses={200: ListQuickevaluationSerializer(many=True)},
|
|
||||||
)
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
queryset = QuickEvaluationModel.objects.filter(
|
|
||||||
is_archive=True
|
|
||||||
).order_by("-created_at")
|
|
||||||
|
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["QuickEvaluation"],
|
|
||||||
summary="Archive or unarchive quick evaluation",
|
|
||||||
description="""
|
|
||||||
Update archive status for quick evaluation.
|
|
||||||
|
|
||||||
- is_archive=true → archive
|
|
||||||
- is_archive=false → remove from archive
|
|
||||||
""",
|
|
||||||
request=ArchiveQuickevaluationSerializer,
|
|
||||||
responses={
|
|
||||||
200: OpenApiResponse(
|
|
||||||
description="Archive status updated successfully"
|
|
||||||
),
|
|
||||||
400: OpenApiResponse(
|
|
||||||
description="Validation error"
|
|
||||||
),
|
|
||||||
404: OpenApiResponse(
|
|
||||||
description="Quick evaluation not found"
|
|
||||||
),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
serializer = self.get_serializer(data=request.data)
|
|
||||||
serializer.is_valid(raise_exception=True)
|
|
||||||
|
|
||||||
validated_data = serializer.validated_data
|
|
||||||
|
|
||||||
obj = get_object_or_404(
|
|
||||||
QuickEvaluationModel,
|
|
||||||
id=validated_data["id"]
|
|
||||||
)
|
|
||||||
|
|
||||||
obj.is_archive = validated_data["is_archive"]
|
|
||||||
obj.save(update_fields=["is_archive"])
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"success": True,
|
|
||||||
"message": "Archive status updated successfully"
|
|
||||||
},
|
|
||||||
status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user