Compare commits
1 Commits
request-ar
...
76563b3ef0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76563b3ef0 |
28
core/apps/evaluation/migrations/0032_certificatemodel.py
Normal file
28
core/apps/evaluation/migrations/0032_certificatemodel.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 6.0.4 on 2026-04-23 11:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('evaluation', '0031_remove_autoevaluationmodel_object_location_city_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='CertificateModel',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateTimeField(auto_now=True)),
|
||||||
|
('title', models.CharField(max_length=255, verbose_name='title')),
|
||||||
|
('file_url', models.URLField(max_length=255, verbose_name='file url')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Certificate',
|
||||||
|
'verbose_name_plural': 'Certificates',
|
||||||
|
'db_table': 'certificate',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 6.0.4 on 2026-04-23 07:22
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0031_remove_autoevaluationmodel_object_location_city_and_more'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='is_archive',
|
|
||||||
field=models.BooleanField(default=False, verbose_name='is archive'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -11,3 +11,4 @@ from .report import * # noqa
|
|||||||
from .request import * # noqa
|
from .request import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
from .certificate import * # noqa
|
||||||
|
|||||||
20
core/apps/evaluation/models/certificate.py
Normal file
20
core/apps/evaluation/models/certificate.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from django.db import models
|
||||||
|
from django_core.models import AbstractBaseModel
|
||||||
|
from model_bakery import baker
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
class CertificateModel(AbstractBaseModel):
|
||||||
|
title = models.CharField(verbose_name=_("title"), max_length=255, blank=False, null=False)
|
||||||
|
file_url = models.URLField(verbose_name=_("file url"), max_length=255, blank=False, null=False)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _baker(cls):
|
||||||
|
return baker.make(cls)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "certificate"
|
||||||
|
verbose_name = _("Certificate")
|
||||||
|
verbose_name_plural = _("Certificates")
|
||||||
@@ -118,10 +118,6 @@ class EvaluationrequestModel(AbstractBaseModel):
|
|||||||
choices=RequestStatus.choices,
|
choices=RequestStatus.choices,
|
||||||
default=RequestStatus.PENDING,
|
default=RequestStatus.PENDING,
|
||||||
)
|
)
|
||||||
is_archive = models.BooleanField(
|
|
||||||
verbose_name=_("is archive"),
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Requests #{self.pk} — {self.get_rate_type_display()}"
|
return f"Requests #{self.pk} — {self.get_rate_type_display()}"
|
||||||
|
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ from .request import * # noqa
|
|||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
from .tech_passport import * # noqa
|
from .tech_passport import * # noqa
|
||||||
|
from .certificate import * # noqa
|
||||||
|
|||||||
1
core/apps/evaluation/serializers/certificate/__init__.py
Normal file
1
core/apps/evaluation/serializers/certificate/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .certificate import * # noqa
|
||||||
12
core/apps/evaluation/serializers/certificate/certificate.py
Normal file
12
core/apps/evaluation/serializers/certificate/certificate.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from core.apps.evaluation.models import CertificateModel
|
||||||
|
|
||||||
|
class BaseCertificateSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CertificateModel
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"title",
|
||||||
|
"file_url"
|
||||||
|
]
|
||||||
@@ -55,7 +55,6 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
"user",
|
"user",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
"is_archive",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_location(self, obj):
|
def get_location(self, obj):
|
||||||
@@ -184,7 +183,3 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
validated_data["location_name"] = str(location_name)
|
validated_data["location_name"] = str(location_name)
|
||||||
validated_data["user"] = self.context["request"].user
|
validated_data["user"] = self.context["request"].user
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
class ArchiveEvaluationrequestSerializer(serializers.Serializer):
|
|
||||||
id = serializers.IntegerField(required=True)
|
|
||||||
is_archive = serializers.BooleanField(required=True)
|
|
||||||
@@ -29,7 +29,7 @@ from .views import (
|
|||||||
DidoxCompanyInfoAPIView,
|
DidoxCompanyInfoAPIView,
|
||||||
TechPassportAPIView,
|
TechPassportAPIView,
|
||||||
EvaluationStatusChange,
|
EvaluationStatusChange,
|
||||||
ArchiveEvaluationrequestView,
|
CertificateView,
|
||||||
)
|
)
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
@@ -54,6 +54,7 @@ router.register("vehicle", VehicleView, basename="vehicle")
|
|||||||
router.register("valuation", ValuationView, basename="valuation")
|
router.register("valuation", ValuationView, basename="valuation")
|
||||||
router.register("property-owner", PropertyOwnerView, basename="property-owner")
|
router.register("property-owner", PropertyOwnerView, basename="property-owner")
|
||||||
router.register("customer", CustomerView, basename="customer")
|
router.register("customer", CustomerView, basename="customer")
|
||||||
|
router.register("certificate", CertificateView, basename="certificate")
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include(router.urls)),
|
path("", include(router.urls)),
|
||||||
path("auto-evaluation/appraisers/", include(
|
path("auto-evaluation/appraisers/", include(
|
||||||
@@ -75,5 +76,4 @@ 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("evaluation-request/archive/", ArchiveEvaluationrequestView.as_view(), name="evaluation-request-archive"),
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ from .valuation import * # noqa
|
|||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
from .didox import * # noqa
|
from .didox import * # noqa
|
||||||
from .tech_passport import * # noqa
|
from .tech_passport import * # noqa
|
||||||
|
from .certificate import * # noqa
|
||||||
|
|||||||
20
core/apps/evaluation/views/certificate.py
Normal file
20
core/apps/evaluation/views/certificate.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from django_core.mixins import BaseViewSetMixin
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
from core.apps.evaluation.models import CertificateModel
|
||||||
|
from core.apps.evaluation.serializers.certificate import BaseCertificateSerializer
|
||||||
|
from rest_framework.filters import SearchFilter
|
||||||
|
|
||||||
|
@extend_schema(tags=["Certificate"])
|
||||||
|
class CertificateView(BaseViewSetMixin, ModelViewSet):
|
||||||
|
queryset = CertificateModel.objects.all()
|
||||||
|
serializer_class = BaseCertificateSerializer
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
filter_backends = [SearchFilter]
|
||||||
|
search_fields = ["title"]
|
||||||
|
|
||||||
|
pagination_class = None
|
||||||
|
|
||||||
|
action_permission_classes = {}
|
||||||
@@ -17,11 +17,8 @@ from core.apps.evaluation.serializers.request import (
|
|||||||
CreateEvaluationrequestSerializer,
|
CreateEvaluationrequestSerializer,
|
||||||
ListEvaluationrequestSerializer,
|
ListEvaluationrequestSerializer,
|
||||||
RetrieveEvaluationrequestSerializer,
|
RetrieveEvaluationrequestSerializer,
|
||||||
ArchiveEvaluationrequestSerializer,
|
|
||||||
)
|
)
|
||||||
from core.apps.evaluation.choices.request import RequestStatus
|
from core.apps.evaluation.choices.request import RequestStatus
|
||||||
from rest_framework.generics import GenericAPIView
|
|
||||||
from drf_spectacular.utils import OpenApiResponse
|
|
||||||
|
|
||||||
|
|
||||||
# class RequestPagination(PageNumberPagination):
|
# class RequestPagination(PageNumberPagination):
|
||||||
@@ -175,76 +172,3 @@ class EvaluationStatusChange(APIView):
|
|||||||
'status': evaluation.status,
|
'status': evaluation.status,
|
||||||
'id': evaluation.pk
|
'id': evaluation.pk
|
||||||
})
|
})
|
||||||
|
|
||||||
@extend_schema(tags=["EvaluationRequest"])
|
|
||||||
class ArchiveEvaluationrequestView(GenericAPIView):
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
def get_serializer_class(self):
|
|
||||||
if self.request.method == "GET":
|
|
||||||
return ListEvaluationrequestSerializer
|
|
||||||
return ArchiveEvaluationrequestSerializer
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["EvaluationRequest"],
|
|
||||||
summary="Get archived evaluation requests list",
|
|
||||||
description="""
|
|
||||||
Returns only archived evaluation requests.
|
|
||||||
|
|
||||||
This endpoint works like evaluation-request/,
|
|
||||||
but only records with is_archive=True are returned.
|
|
||||||
""",
|
|
||||||
responses={200: ListEvaluationrequestSerializer(many=True)},
|
|
||||||
)
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
queryset = EvaluationrequestModel.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=["EvaluationRequest"],
|
|
||||||
summary="Archive or unarchive evaluation request",
|
|
||||||
description="""
|
|
||||||
Update archive status for evaluation request.
|
|
||||||
|
|
||||||
- is_archive=true → archive
|
|
||||||
- is_archive=false → remove from archive
|
|
||||||
""",
|
|
||||||
request=ArchiveEvaluationrequestSerializer,
|
|
||||||
responses={
|
|
||||||
200: OpenApiResponse(
|
|
||||||
description="Archive status updated successfully"
|
|
||||||
),
|
|
||||||
400: OpenApiResponse(
|
|
||||||
description="Validation error"
|
|
||||||
),
|
|
||||||
404: OpenApiResponse(
|
|
||||||
description="Evaluation request 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(
|
|
||||||
EvaluationrequestModel,
|
|
||||||
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