Compare commits
68 Commits
request-ar
...
7e778d3a3e
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e778d3a3e | |||
|
|
81a4287db1 | ||
|
|
e560fdaf2d | ||
|
|
0d96167a7b | ||
|
|
ae65d9d793 | ||
|
|
5249f7e6f7 | ||
|
|
e1b771e166 | ||
|
|
eded642bd7 | ||
| f830235813 | |||
|
|
a62cf3a1ee | ||
|
|
2f471173c3 | ||
| 3838fbaa47 | |||
|
|
b02078e618 | ||
|
|
1f59347d87 | ||
|
|
fe40057d95 | ||
| 550da049b9 | |||
|
|
bdd5aa9ce2 | ||
|
|
bd27205252 | ||
| 34aba90ebd | |||
|
|
260bc9101e | ||
|
|
f46dac515a | ||
|
|
c6fc150162 | ||
| 7272ef3fce | |||
|
|
1db936126d | ||
| 5e1b02064e | |||
|
|
4e242a4358 | ||
| bcb453d52a | |||
| 039ca92031 | |||
|
|
21bb61e51c | ||
|
|
c9d60acfc9 | ||
|
|
127a2073f8 | ||
| 1ad2016790 | |||
|
|
3fd0f9959b | ||
|
|
84cc11fe2a | ||
|
|
deebae384c | ||
|
|
2b5238f3c8 | ||
|
|
988d07f4b6 | ||
|
|
e27a9b7f11 | ||
|
|
c89f2b32af | ||
|
|
82489cf64c | ||
| 88dedd85c7 | |||
|
|
fb275a091a | ||
|
|
af559dadda | ||
|
|
190480b6f7 | ||
| 1a985ffa4b | |||
|
|
3b62c5a7bf | ||
|
|
d2f8d73cdd | ||
|
|
c4b2a80b2e | ||
|
|
07f8d55966 | ||
| b0b4ccfeee | |||
|
|
ccefe9c119 | ||
|
|
6456283f72 | ||
|
|
6eed2d998e | ||
| 2c82691166 | |||
|
|
7a88e39b96 | ||
|
|
7961fd76de | ||
|
|
dc622ce305 | ||
|
|
6e0718c5db | ||
|
|
32d3bea234 | ||
|
|
129827b495 | ||
|
|
50cc555783 | ||
|
|
76563b3ef0 | ||
|
|
207363dc6a | ||
| 2a08ad9662 | |||
|
|
049cd6ff25 | ||
|
|
5cf4b950fb | ||
|
|
4fee037467 | ||
|
|
b8021c7728 |
@@ -75,7 +75,3 @@ STORAGE_PROTOCOL=http:
|
||||
|
||||
# Didox configs
|
||||
DIDOX_PARTNER_TOKEN=...
|
||||
|
||||
|
||||
|
||||
# Celery configs
|
||||
4
.github/workflows/deploy.yaml
vendored
4
.github/workflows/deploy.yaml
vendored
@@ -8,7 +8,6 @@ on:
|
||||
env:
|
||||
PROJECT_NAME: sifatbaho
|
||||
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
@@ -95,7 +94,6 @@ jobs:
|
||||
sed -i "s|image: .*/${{ env.PROJECT_NAME }}:.*|image: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}:${{ github.run_number }}|g" stack.yaml
|
||||
sed -i 's/return HttpResponse("OK.*"/return HttpResponse("OK: #${{ github.sha }}"/' config/urls.py
|
||||
|
||||
|
||||
- name: Commit and push updated version
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
@@ -154,6 +152,6 @@ jobs:
|
||||
"DB_HOST=postgres" \
|
||||
"DB_NAME=sifatbahodb" \
|
||||
"DB_PORT=5432" \
|
||||
"DIDOX_TOKEN=${{ secrets.DIDOX_TOKEN }}"
|
||||
"DIDOX_PARTNER_TOKEN=${{ secrets.DIDOX_TOKEN }}"
|
||||
export PORT=8085
|
||||
docker stack deploy -c stack.yaml ${{ env.PROJECT_NAME }} --with-registry-auth
|
||||
|
||||
@@ -13,7 +13,7 @@ from config.env import env
|
||||
|
||||
|
||||
def home(request):
|
||||
return HttpResponse("OK: #d4e6d80c86fcf4422f71238c6552dfa4b42f9737")
|
||||
return HttpResponse("OK: #f83023581352d6c1a13ed27703ccd356a1f40df9")
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
60
core/apps/accounts/models/permission.py
Normal file
60
core/apps/accounts/models/permission.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_core.models import AbstractBaseModel
|
||||
|
||||
|
||||
class PermissionToAction(AbstractBaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} - {self.code}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Harakatlar uchun ruxsatnoma')
|
||||
verbose_name_plural = _('Harakatlar uchun ruxsatnomalar')
|
||||
|
||||
|
||||
class PermissionToTab(AbstractBaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
permission_to_actions = models.ManyToManyField(
|
||||
PermissionToAction, related_name='permission_to_tabs'
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name} - {self.code}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Bo'lim uchun ruxsatnoma")
|
||||
verbose_name_plural = _("Bo'lim uchun ruxsatnomalar")
|
||||
|
||||
|
||||
class Permission(AbstractBaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
permission_tab = models.ManyToManyField(PermissionToTab, related_name='permissions')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name} - {self.code}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Sahifa uchun ruxsatnoma')
|
||||
verbose_name_plural = _('Sahifa uchun ruxsatnomalar')
|
||||
|
||||
class Role(models.Model):
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
permissions = models.ManyToManyField(Permission, related_name='roles', blank=True)
|
||||
permission_to_tabs = models.ManyToManyField(PermissionToTab, related_name='roles', blank=True)
|
||||
permission_to_actions = models.ManyToManyField(
|
||||
PermissionToAction, related_name='roles', blank=True
|
||||
)
|
||||
comment = models.CharField(max_length=200, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Rol')
|
||||
verbose_name_plural = _('Rollar')
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django.contrib.auth import models as auth_models
|
||||
from django.db import models
|
||||
|
||||
from .permission import Role
|
||||
from ..choices import RoleChoice
|
||||
from ..managers import UserManager
|
||||
|
||||
@@ -17,6 +18,7 @@ class User(auth_models.AbstractUser):
|
||||
default=RoleChoice.USER,
|
||||
)
|
||||
avatar = models.ImageField(upload_to="avatars/", null=True, blank=True)
|
||||
permission = models.ForeignKey(Role, on_delete=models.SET_NULL, null=True, blank=True, related_name='users')
|
||||
|
||||
USERNAME_FIELD = "phone"
|
||||
objects = UserManager()
|
||||
|
||||
26
core/apps/accounts/serializers/permission.py
Normal file
26
core/apps/accounts/serializers/permission.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.accounts.models.permission import PermissionToAction, PermissionToTab, Permission, Role
|
||||
|
||||
|
||||
class PermissionToActionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PermissionToAction
|
||||
fields = "__all__"
|
||||
|
||||
class PermissionToTabSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PermissionToTab
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class PermissionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Permission
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class RoleSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Role
|
||||
fields = '__all__'
|
||||
@@ -30,3 +30,28 @@ class UserUpdateSerializer(serializers.ModelSerializer):
|
||||
"last_name",
|
||||
"avatar"
|
||||
]
|
||||
|
||||
class AdminUserSerializer(serializers.ModelSerializer):
|
||||
avatar = serializers.SerializerMethodField(method_name='get_avatar')
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = "__all__"
|
||||
|
||||
def get_avatar(self, obj):
|
||||
request = self.context.get('request')
|
||||
if obj.avatar:
|
||||
return request.build_absolute_uri(obj.avatar.url)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
class UserCreateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = [
|
||||
"phone",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"password",
|
||||
"role"]
|
||||
@@ -4,14 +4,22 @@ Accounts app urls
|
||||
|
||||
from django.urls import path, include
|
||||
from rest_framework_simplejwt import views as jwt_views
|
||||
from .views import RegisterView, ResetPasswordView, MeView, ChangePasswordView, UserListApiView, AdminUserListApiView
|
||||
from .views import RegisterView, ResetPasswordView, MeView, ChangePasswordView, UserListApiView, AdminUserListApiView, \
|
||||
AdminUserView, AdminCreateAPIView, AdminUpdateAPIView
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .views.permission import PermissionToActionViewSet, PermissionToTabViewSet, PermissionViewSet, RoleViewSet
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("auth", RegisterView, basename="auth")
|
||||
router.register("auth", ResetPasswordView, basename="reset-password")
|
||||
router.register("auth", MeView, basename="me")
|
||||
router.register("auth", ChangePasswordView, basename="change-password")
|
||||
router.register("user", AdminUserView, basename="user-crud")
|
||||
router.register("action", PermissionToActionViewSet, basename="action")
|
||||
router.register("permission-to-tab", PermissionToTabViewSet, basename="permission-to-tab")
|
||||
router.register("permission", PermissionViewSet, basename="permission")
|
||||
router.register("permission-role", RoleViewSet, basename="permission-role")
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
@@ -25,4 +33,6 @@ urlpatterns = [
|
||||
),
|
||||
path("user/list/", UserListApiView.as_view(), name="user-list"),
|
||||
path("admin-user/list/", AdminUserListApiView.as_view(), name="admin-user-list"),
|
||||
path("admin/create/", AdminCreateAPIView.as_view(), name="user-create"),
|
||||
path("admin/update/", AdminUpdateAPIView.as_view(), name="user-update"),
|
||||
]
|
||||
|
||||
42
core/apps/accounts/views/permission.py
Normal file
42
core/apps/accounts/views/permission.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from core.apps.accounts.models.permission import PermissionToAction, PermissionToTab, Permission, Role
|
||||
from core.apps.accounts.serializers.permission import PermissionToActionSerializer, PermissionToTabSerializer, \
|
||||
PermissionSerializer, RoleSerializer
|
||||
|
||||
|
||||
@extend_schema(tags=["permission"])
|
||||
class PermissionToActionViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = PermissionToAction.objects.all()
|
||||
serializer_class = PermissionToActionSerializer
|
||||
|
||||
action_serializer_class = {
|
||||
'create': PermissionToActionSerializer,
|
||||
'update': PermissionToActionSerializer,
|
||||
}
|
||||
|
||||
action_permission_classes = {
|
||||
'create': [AllowAny],
|
||||
'destroy': [IsAdminUser],
|
||||
}
|
||||
|
||||
|
||||
@extend_schema(tags=["permission"])
|
||||
class PermissionToTabViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = PermissionToTab.objects.all()
|
||||
serializer_class = PermissionToTabSerializer
|
||||
|
||||
|
||||
|
||||
@extend_schema(tags=["permission"])
|
||||
class PermissionViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = Permission.objects.all()
|
||||
serializer_class = PermissionSerializer
|
||||
|
||||
|
||||
class RoleViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = Role.objects.all()
|
||||
serializer_class = RoleSerializer
|
||||
@@ -1,15 +1,19 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework import generics, filters
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
from core.apps.accounts.serializers.user import UserSerializer
|
||||
from core.apps.accounts.choices.user import RoleChoice
|
||||
from core.apps.accounts.serializers.user import UserSerializer, AdminUserSerializer, UserCreateSerializer
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
@extend_schema(tags=['User'])
|
||||
class UserListApiView(generics.ListAPIView):
|
||||
queryset = User.objects.filter(role=RoleChoice.USER)
|
||||
@@ -29,3 +33,50 @@ class AdminUserListApiView(generics.ListAPIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['phone', 'first_name', 'last_name']
|
||||
|
||||
|
||||
@extend_schema(tags=["User"], request=AdminUserSerializer)
|
||||
class AdminUserView(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = User.objects.filter(role=RoleChoice.USER)
|
||||
serializer_class = AdminUserSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['phone', 'first_name', 'last_name']
|
||||
|
||||
def serializer_context(self):
|
||||
return self.serializer_class(context={"request": self.request})
|
||||
|
||||
|
||||
@extend_schema(tags=['User'],
|
||||
responses={200: UserSerializer},
|
||||
request=UserCreateSerializer)
|
||||
class AdminCreateAPIView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
if request.user.role not in (RoleChoice.SUPERUSER, RoleChoice.ADMIN):
|
||||
return Response({'detail': 'Forbidden'}, status=403)
|
||||
|
||||
serializer = UserCreateSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
|
||||
return Response(serializer.data, status=201)
|
||||
|
||||
|
||||
@extend_schema(tags=['User'],
|
||||
responses={200: UserSerializer},
|
||||
request=UserCreateSerializer)
|
||||
class AdminUpdateAPIView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def put(self, request, pk):
|
||||
if request.user.role not in (RoleChoice.SUPERUSER, RoleChoice.ADMIN):
|
||||
return Response({'detail': 'Forbidden'}, status=403)
|
||||
|
||||
user = get_object_or_404(User, pk=pk)
|
||||
serializer = UserCreateSerializer(user, data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
|
||||
return Response(serializer.data, status=200)
|
||||
|
||||
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',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 6.0.4 on 2026-04-23 07:24
|
||||
|
||||
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='quickevaluationmodel',
|
||||
name='is_archive',
|
||||
field=models.BooleanField(default=False, verbose_name='is archive'),
|
||||
),
|
||||
]
|
||||
15
core/apps/evaluation/migrations/0033_merge_20260423_1622.py
Normal file
15
core/apps/evaluation/migrations/0033_merge_20260423_1622.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Generated by Django 6.0.4 on 2026-04-23 11:22
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('evaluation', '0032_certificatemodel'),
|
||||
('evaluation', '0032_evaluationrequestmodel_is_archive'),
|
||||
('evaluation', '0032_quickevaluationmodel_is_archive'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 6.0.4 on 2026-04-23 13:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('evaluation', '0033_merge_20260423_1622'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='certificatemodel',
|
||||
name='file_url',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='certificatemodel',
|
||||
name='file',
|
||||
field=models.FileField(blank=True, null=True, upload_to='certificates/', verbose_name='file'),
|
||||
),
|
||||
]
|
||||
@@ -11,3 +11,4 @@ from .report import * # noqa
|
||||
from .request import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .certificate import * # noqa
|
||||
|
||||
@@ -267,6 +267,12 @@ class AutoEvaluationModel(AbstractBaseModel):
|
||||
choices=AutoEvaluationStatus.choices,
|
||||
default=AutoEvaluationStatus.CREATED,
|
||||
)
|
||||
is_archived = models.BooleanField(
|
||||
verbose_name=_("is archived"),
|
||||
default=False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"Auto Evaluation {self.registration_number or self.pk}"
|
||||
|
||||
30
core/apps/evaluation/models/certificate.py
Normal file
30
core/apps/evaluation/models/certificate.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django.db import models
|
||||
from django_core.models import AbstractBaseModel
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from model_bakery import baker
|
||||
|
||||
|
||||
class CertificateModel(AbstractBaseModel):
|
||||
title = models.CharField(
|
||||
verbose_name=_("title"),
|
||||
max_length=255
|
||||
)
|
||||
|
||||
file = models.FileField(
|
||||
verbose_name=_("file"),
|
||||
upload_to="certificates/",
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
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")
|
||||
@@ -132,6 +132,11 @@ class QuickEvaluationModel(AbstractBaseModel):
|
||||
default=QuickEvaluationStatus.CREATED,
|
||||
)
|
||||
|
||||
is_archive = models.BooleanField(
|
||||
verbose_name=_("is archive"),
|
||||
default=False,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Quick Evaluation {self.pk} by {self.created_by}"
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@ from .request import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .tech_passport import * # noqa
|
||||
from .certificate import * # noqa
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import re
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.evaluation.models import AutoEvaluationModel,ReferenceitemModel, EvaluationrequestModel
|
||||
from core.apps.evaluation.serializers.reference import ListReferenceitemSerializer
|
||||
from core.apps.evaluation.choices.request import RequestStatus
|
||||
from core.apps.evaluation.models import AutoEvaluationModel, ReferenceitemModel, EvaluationrequestModel
|
||||
from core.apps.evaluation.serializers.reference import ListReferenceitemSerializer
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class BaseAutoevaluationSerializer(serializers.ModelSerializer):
|
||||
status_display = serializers.CharField(source="get_status_display", read_only=True)
|
||||
object_type_display = serializers.CharField(source="get_object_type_display", read_only=True, default=None)
|
||||
object_owner_type_display = serializers.CharField(source="get_object_owner_type_display", read_only=True, default=None)
|
||||
object_owner_type_display = serializers.CharField(source="get_object_owner_type_display", read_only=True,
|
||||
default=None)
|
||||
rate_type = ListReferenceitemSerializer(read_only=True)
|
||||
value_determined = ListReferenceitemSerializer(read_only=True)
|
||||
property_rights = ListReferenceitemSerializer(read_only=True)
|
||||
@@ -72,6 +74,7 @@ class ListAutoevaluationSerializer(BaseAutoevaluationSerializer):
|
||||
class RetrieveAutoevaluationSerializer(BaseAutoevaluationSerializer):
|
||||
car_type_display = serializers.CharField(source="get_car_type_display", read_only=True, default=None)
|
||||
car_wheel_display = serializers.CharField(source="get_car_wheel_display", read_only=True, default=None)
|
||||
|
||||
# object_location_highways_display = serializers.CharField(
|
||||
# source="get_object_location_highways_display", read_only=True, default=None
|
||||
# )
|
||||
@@ -141,7 +144,6 @@ class UpdateAutoevaluationSerializer(serializers.ModelSerializer):
|
||||
allow_null=True,
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
model = AutoEvaluationModel
|
||||
fields = [
|
||||
@@ -222,6 +224,7 @@ class UpdateAutoevaluationSerializer(serializers.ModelSerializer):
|
||||
|
||||
return attrs
|
||||
|
||||
|
||||
class CreateAutoevaluationSerializer(serializers.ModelSerializer):
|
||||
property_rights = serializers.PrimaryKeyRelatedField(
|
||||
queryset=ReferenceitemModel.objects.all(),
|
||||
@@ -254,7 +257,6 @@ class CreateAutoevaluationSerializer(serializers.ModelSerializer):
|
||||
allow_null=True,
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
model = AutoEvaluationModel
|
||||
fields = [
|
||||
@@ -356,3 +358,13 @@ class AutoEvaluationAppraisersSerializer(serializers.Serializer):
|
||||
raise serializers.ValidationError("Invalid appraisers IDs.")
|
||||
data['users'] = users
|
||||
return data
|
||||
|
||||
class AutoEvaluationSerializer(serializers.Serializer):
|
||||
brand = serializers.CharField()
|
||||
brand_model = serializers.CharField()
|
||||
year = serializers.CharField()
|
||||
color = serializers.CharField()
|
||||
transmission = serializers.CharField()
|
||||
condition = serializers.CharField()
|
||||
fuel_type = serializers.CharField()
|
||||
mileage = serializers.CharField()
|
||||
11
core/apps/evaluation/serializers/auto/AvgCost.py
Normal file
11
core/apps/evaluation/serializers/auto/AvgCost.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class AvgCostSerializer(serializers.Serializer):
|
||||
brand = serializers.CharField(max_length=100)
|
||||
condition = serializers.CharField(max_length=100)
|
||||
model = serializers.CharField(max_length=100)
|
||||
complication = serializers.CharField(max_length=100)
|
||||
manufacture_date = serializers.DateField()
|
||||
distance_covered = serializers.IntegerField()
|
||||
color = serializers.CharField(max_length=100)
|
||||
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
|
||||
22
core/apps/evaluation/serializers/certificate/certificate.py
Normal file
22
core/apps/evaluation/serializers/certificate/certificate.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from rest_framework import serializers
|
||||
from core.apps.evaluation.models import CertificateModel
|
||||
|
||||
|
||||
class BaseCertificateSerializer(serializers.ModelSerializer):
|
||||
file = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = CertificateModel
|
||||
fields = [
|
||||
"id",
|
||||
"title",
|
||||
"file",
|
||||
]
|
||||
|
||||
def get_file(self, obj):
|
||||
if obj.file:
|
||||
request = self.context.get('request')
|
||||
if request:
|
||||
return request.build_absolute_uri(obj.file.url)
|
||||
return obj.file.url
|
||||
return None
|
||||
@@ -38,7 +38,8 @@ class BaseQuickevaluationSerializer(serializers.ModelSerializer):
|
||||
"state_car_name",
|
||||
"created_at",
|
||||
"distance_covered",
|
||||
"tex_passport_serie_num"
|
||||
"tex_passport_serie_num",
|
||||
"is_archive"
|
||||
]
|
||||
|
||||
|
||||
@@ -125,3 +126,5 @@ class CreateQuickevaluationSerializer(serializers.ModelSerializer):
|
||||
if request and request.user and request.user.is_authenticated:
|
||||
validated_data["created_by"] = request.user
|
||||
return super().create(validated_data)
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ from .views import (
|
||||
DidoxCompanyInfoAPIView,
|
||||
TechPassportAPIView,
|
||||
EvaluationStatusChange,
|
||||
ArchiveEvaluationrequestView,
|
||||
CertificateView,
|
||||
ArchiveEvaluationrequestView, GetArchivedAutoEvaluationListAPIView, ArchivedAutoEvaluation,
|
||||
GetArchivedQuickevaluationListAPIView, ChangeQuickevaluationAPIView, ArchivedReqEvaluation,
|
||||
GetArchivedReqEvaluationListAPIView,
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
@@ -54,6 +57,7 @@ router.register("vehicle", VehicleView, basename="vehicle")
|
||||
router.register("valuation", ValuationView, basename="valuation")
|
||||
router.register("property-owner", PropertyOwnerView, basename="property-owner")
|
||||
router.register("customer", CustomerView, basename="customer")
|
||||
router.register("certificate", CertificateView, basename="certificate")
|
||||
urlpatterns = [
|
||||
path("", include(router.urls)),
|
||||
path("auto-evaluation/appraisers/", include(
|
||||
@@ -75,5 +79,21 @@ urlpatterns = [
|
||||
),
|
||||
path("evaluation-request/<int:pk>/change-status/", EvaluationStatusChange.as_view(),
|
||||
name="evaluation-change-status"),
|
||||
path("evaluation-request/archive/", ArchiveEvaluationrequestView.as_view(), name="evaluation-request-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("archived-evaluvation/", GetArchivedAutoEvaluationListAPIView.as_view(),
|
||||
name="archived-evaluation"),
|
||||
|
||||
path("auto-evaluvation-change-status/<int:pk>", ArchivedAutoEvaluation.as_view(),
|
||||
name="archived-evaluation"),
|
||||
|
||||
path("req-evaluvation-change-status/<int:pk>", ArchivedReqEvaluation.as_view(),
|
||||
name="archived-req-evaluation"),
|
||||
|
||||
path("req-evaluvation-change-status/", GetArchivedReqEvaluationListAPIView.as_view(),
|
||||
name="archived-req-evaluation"),
|
||||
|
||||
]
|
||||
|
||||
@@ -13,3 +13,4 @@ from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .didox import * # noqa
|
||||
from .tech_passport import * # noqa
|
||||
from .certificate import * # noqa
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
from django.db.models import Q
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from drf_spectacular.utils import extend_schema, OpenApiParameter
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.generics import GenericAPIView, ListAPIView
|
||||
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.views import APIView
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from core.apps.accounts.serializers.user import UserSerializer
|
||||
from core.apps.evaluation.filters.auto import AutoevaluationFilter
|
||||
@@ -154,3 +155,21 @@ class AutoEvaluationListAppraisersView(GenericAPIView):
|
||||
return self.get_paginated_response(serializer.data)
|
||||
except Exception as e:
|
||||
return Response({"error": str(e)}, status=500)
|
||||
|
||||
|
||||
@extend_schema(tags=["AutoEvaluation"])
|
||||
class GetArchivedAutoEvaluationListAPIView(ListAPIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
def get_queryset(self):
|
||||
return AutoEvaluationModel.objects.filter(is_archived=True)
|
||||
|
||||
|
||||
@extend_schema(tags=["AutoEvaluation"])
|
||||
class ArchivedAutoEvaluation(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request, pk):
|
||||
auto_evaluation = get_object_or_404(AutoEvaluationModel, pk=pk)
|
||||
auto_evaluation.is_archived = request.data["is_archived"]
|
||||
auto_evaluation.save()
|
||||
return Response({"success": True}, status=200)
|
||||
|
||||
18
core/apps/evaluation/views/avg_cost.py
Normal file
18
core/apps/evaluation/views/avg_cost.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from rest_framework import generics
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import permissions
|
||||
|
||||
from core.apps.evaluation.serializers.auto.AvgCost import AvgCostSerializer
|
||||
from core.services.grpc.auto import get_auto_avg_cost
|
||||
|
||||
|
||||
class AvgCostView(generics.GenericAPIView):
|
||||
serializer_class = AvgCostSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def post(self):
|
||||
serializer = self.get_serializer(data=self.request.data)
|
||||
if serializer.is_valid():
|
||||
avg_cost = get_auto_avg_cost(serializer.validated_data)
|
||||
return Response(avg_cost, status=200)
|
||||
return Response(serializer.errors, status=400)
|
||||
23
core/apps/evaluation/views/certificate.py
Normal file
23
core/apps/evaluation/views/certificate.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
from rest_framework.parsers import MultiPartParser, FormParser
|
||||
|
||||
@extend_schema(tags=["Certificate"],request=BaseCertificateSerializer)
|
||||
class CertificateView(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = CertificateModel.objects.all()
|
||||
serializer_class = BaseCertificateSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
parser_classes = [MultiPartParser, FormParser]
|
||||
|
||||
filter_backends = [SearchFilter]
|
||||
search_fields = ["title"]
|
||||
|
||||
pagination_class = None
|
||||
|
||||
action_permission_classes = {}
|
||||
@@ -1,6 +1,6 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.generics import GenericAPIView
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from core.services.didox import DidoxService
|
||||
|
||||
class DidoxCompanyInfoAPIView(GenericAPIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [AllowAny]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@extend_schema(
|
||||
tags=["Didox"],
|
||||
|
||||
0
core/apps/evaluation/views/permission.py
Normal file
0
core/apps/evaluation/views/permission.py
Normal file
@@ -1,9 +1,14 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework import status
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.parsers import FormParser, MultiPartParser
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from core.apps.evaluation.filters.quick import QuickevaluationFilter
|
||||
@@ -20,7 +25,7 @@ class QuickEvaluationView(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = QuickEvaluationModel.objects.select_related(
|
||||
"created_by", "brand", "marka", "color", "fuel_type",
|
||||
"body_type", "state_car", "car_position",
|
||||
).all()
|
||||
).filter(is_archive=False)
|
||||
serializer_class = ListQuickevaluationSerializer
|
||||
permission_classes = [AllowAny]
|
||||
parser_classes = [MultiPartParser, FormParser]
|
||||
@@ -50,3 +55,28 @@ class QuickEvaluationView(BaseViewSetMixin, ModelViewSet):
|
||||
"retrieve": RetrieveQuickevaluationSerializer,
|
||||
"create": CreateQuickevaluationSerializer,
|
||||
}
|
||||
|
||||
|
||||
@extend_schema(tags=["QuickEvaluation"])
|
||||
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]
|
||||
|
||||
def get_queryset(self):
|
||||
return QuickEvaluationModel.objects.filter(is_archived=True)
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from drf_spectacular.utils import OpenApiResponse
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework import status
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.generics import GenericAPIView, ListAPIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import status
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from core.apps.accounts.choices import RoleChoice
|
||||
from core.apps.evaluation.choices.request import RequestStatus
|
||||
from core.apps.evaluation.filters.request import EvaluationrequestFilter
|
||||
from core.apps.evaluation.models import EvaluationrequestModel
|
||||
from core.apps.evaluation.serializers.request import (
|
||||
@@ -19,9 +21,6 @@ from core.apps.evaluation.serializers.request import (
|
||||
RetrieveEvaluationrequestSerializer,
|
||||
ArchiveEvaluationrequestSerializer,
|
||||
)
|
||||
from core.apps.evaluation.choices.request import RequestStatus
|
||||
from rest_framework.generics import GenericAPIView
|
||||
from drf_spectacular.utils import OpenApiResponse
|
||||
|
||||
|
||||
# class RequestPagination(PageNumberPagination):
|
||||
@@ -85,7 +84,6 @@ class EvaluationrequestView(BaseViewSetMixin, ModelViewSet):
|
||||
).order_by("-created_at")
|
||||
|
||||
|
||||
|
||||
@extend_schema(tags=["EvaluationRequest"])
|
||||
class AdminEvaluationrequestView(BaseViewSetMixin, ModelViewSet):
|
||||
serializer_class = ListEvaluationrequestSerializer
|
||||
@@ -133,7 +131,8 @@ class AdminEvaluationrequestView(BaseViewSetMixin, ModelViewSet):
|
||||
}
|
||||
|
||||
def get_queryset(self):
|
||||
return EvaluationrequestModel.objects.select_related("value_determined", "rate_goal", "property_rights", "form_ownership", "user").order_by("-created_at")
|
||||
return EvaluationrequestModel.objects.select_related("value_determined", "rate_goal", "property_rights",
|
||||
"form_ownership", "user").order_by("-created_at")
|
||||
|
||||
def serializer_context(self):
|
||||
return self.serializer_class(context={"request": self.request})
|
||||
@@ -149,7 +148,6 @@ class EvaluationStatusChange(APIView):
|
||||
|
||||
evaluation = get_object_or_404(EvaluationrequestModel, pk=pk)
|
||||
|
||||
|
||||
status_value = request.data.get('status')
|
||||
if not status_value:
|
||||
return Response({'detail': 'Status is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
@@ -176,6 +174,7 @@ class EvaluationStatusChange(APIView):
|
||||
'id': evaluation.pk
|
||||
})
|
||||
|
||||
|
||||
@extend_schema(tags=["EvaluationRequest"])
|
||||
class ArchiveEvaluationrequestView(GenericAPIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
@@ -247,4 +246,25 @@ class ArchiveEvaluationrequestView(GenericAPIView):
|
||||
"message": "Archive status updated successfully"
|
||||
},
|
||||
status=status.HTTP_200_OK
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["EvaluationRequest"])
|
||||
class GetArchivedReqEvaluationListAPIView(ListAPIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
return EvaluationrequestModel.objects.filter(is_archived=True)
|
||||
|
||||
|
||||
@extend_schema(tags=["EvaluationRequest"])
|
||||
class ArchivedReqEvaluation(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request, pk):
|
||||
req_evaluation = get_object_or_404(EvaluationrequestModel, pk=pk)
|
||||
req_evaluation.is_archived = request.data["is_archived"]
|
||||
req_evaluation.save()
|
||||
return Response({"success": True,
|
||||
"status": req_evaluation.status,
|
||||
"id": req_evaluation.pk}, status=200)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.generics import GenericAPIView
|
||||
|
||||
from drf_spectacular.utils import (
|
||||
@@ -14,7 +14,7 @@ from ..serializers import TechPassportSerializer
|
||||
|
||||
class TechPassportAPIView(GenericAPIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [AllowAny]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@extend_schema(
|
||||
tags=["Tech Passport"],
|
||||
|
||||
45
core/generated/auto_pb2.py
Normal file
45
core/generated/auto_pb2.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# NO CHECKED-IN PROTOBUF GENCODE
|
||||
# source: auto.proto
|
||||
# Protobuf Python Version: 6.31.1
|
||||
"""Generated protocol buffer code."""
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import descriptor_pool as _descriptor_pool
|
||||
from google.protobuf import runtime_version as _runtime_version
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf.internal import builder as _builder
|
||||
_runtime_version.ValidateProtobufRuntimeVersion(
|
||||
_runtime_version.Domain.PUBLIC,
|
||||
6,
|
||||
31,
|
||||
1,
|
||||
'',
|
||||
'auto.proto'
|
||||
)
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\nauto.proto\x12\x04\x61uto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xba\x01\n\x12\x41utoAvgCostRequest\x12\r\n\x05\x62rand\x18\x01 \x01(\t\x12\x11\n\tcondition\x18\x02 \x01(\t\x12\r\n\x05model\x18\x03 \x01(\t\x12\x14\n\x0c\x63omplication\x18\x04 \x01(\t\x12\x34\n\x10manufacture_date\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x18\n\x10\x64istance_covered\x18\x06 \x01(\t\x12\r\n\x05\x63olor\x18\x07 \x01(\t\"$\n\x13\x41\x64ImageListResponse\x12\r\n\x05image\x18\x01 \x01(\t\"t\n\x0e\x41\x64ListResponse\x12\n\n\x02id\x18\x01 \x01(\t\x12)\n\x06images\x18\x02 \x03(\x0b\x32\x19.auto.AdImageListResponse\x12\r\n\x05title\x18\x03 \x01(\t\x12\r\n\x05price\x18\x04 \x01(\t\x12\r\n\x05model\x18\x05 \x01(\t\"J\n\x13\x41utoAvgCostResponse\x12\x10\n\x08\x61vg_cost\x18\x01 \x01(\x01\x12!\n\x03\x61\x64s\x18\x02 \x03(\x0b\x32\x14.auto.AdListResponse2X\n\x12\x41utoAvgCostService\x12\x42\n\x0b\x41utoAvgCost\x12\x18.auto.AutoAvgCostRequest\x1a\x19.auto.AutoAvgCostResponseb\x06proto3')
|
||||
|
||||
_globals = globals()
|
||||
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
||||
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'auto_pb2', _globals)
|
||||
if not _descriptor._USE_C_DESCRIPTORS:
|
||||
DESCRIPTOR._loaded_options = None
|
||||
_globals['_AUTOAVGCOSTREQUEST']._serialized_start=54
|
||||
_globals['_AUTOAVGCOSTREQUEST']._serialized_end=240
|
||||
_globals['_ADIMAGELISTRESPONSE']._serialized_start=242
|
||||
_globals['_ADIMAGELISTRESPONSE']._serialized_end=278
|
||||
_globals['_ADLISTRESPONSE']._serialized_start=280
|
||||
_globals['_ADLISTRESPONSE']._serialized_end=396
|
||||
_globals['_AUTOAVGCOSTRESPONSE']._serialized_start=398
|
||||
_globals['_AUTOAVGCOSTRESPONSE']._serialized_end=472
|
||||
_globals['_AUTOAVGCOSTSERVICE']._serialized_start=474
|
||||
_globals['_AUTOAVGCOSTSERVICE']._serialized_end=562
|
||||
# @@protoc_insertion_point(module_scope)
|
||||
97
core/generated/auto_pb2_grpc.py
Normal file
97
core/generated/auto_pb2_grpc.py
Normal file
@@ -0,0 +1,97 @@
|
||||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
||||
"""Client and server classes corresponding to protobuf-defined services."""
|
||||
import grpc
|
||||
import warnings
|
||||
|
||||
from core.generated import auto_pb2 as auto__pb2
|
||||
|
||||
GRPC_GENERATED_VERSION = '1.80.0'
|
||||
GRPC_VERSION = grpc.__version__
|
||||
_version_not_supported = False
|
||||
|
||||
try:
|
||||
from grpc._utilities import first_version_is_lower
|
||||
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
|
||||
except ImportError:
|
||||
_version_not_supported = True
|
||||
|
||||
if _version_not_supported:
|
||||
raise RuntimeError(
|
||||
f'The grpc package installed is at version {GRPC_VERSION},'
|
||||
+ ' but the generated code in auto_pb2_grpc.py depends on'
|
||||
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
|
||||
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
|
||||
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
|
||||
)
|
||||
|
||||
|
||||
class AutoAvgCostServiceStub(object):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
|
||||
def __init__(self, channel):
|
||||
"""Constructor.
|
||||
|
||||
Args:
|
||||
channel: A grpc.Channel.
|
||||
"""
|
||||
self.AutoAvgCost = channel.unary_unary(
|
||||
'/auto.AutoAvgCostService/AutoAvgCost',
|
||||
request_serializer=auto__pb2.AutoAvgCostRequest.SerializeToString,
|
||||
response_deserializer=auto__pb2.AutoAvgCostResponse.FromString,
|
||||
_registered_method=True)
|
||||
|
||||
|
||||
class AutoAvgCostServiceServicer(object):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
|
||||
def AutoAvgCost(self, request, context):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
|
||||
def add_AutoAvgCostServiceServicer_to_server(servicer, server):
|
||||
rpc_method_handlers = {
|
||||
'AutoAvgCost': grpc.unary_unary_rpc_method_handler(
|
||||
servicer.AutoAvgCost,
|
||||
request_deserializer=auto__pb2.AutoAvgCostRequest.FromString,
|
||||
response_serializer=auto__pb2.AutoAvgCostResponse.SerializeToString,
|
||||
),
|
||||
}
|
||||
generic_handler = grpc.method_handlers_generic_handler(
|
||||
'auto.AutoAvgCostService', rpc_method_handlers)
|
||||
server.add_generic_rpc_handlers((generic_handler,))
|
||||
server.add_registered_method_handlers('auto.AutoAvgCostService', rpc_method_handlers)
|
||||
|
||||
|
||||
# This class is part of an EXPERIMENTAL API.
|
||||
class AutoAvgCostService(object):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
|
||||
@staticmethod
|
||||
def AutoAvgCost(request,
|
||||
target,
|
||||
options=(),
|
||||
channel_credentials=None,
|
||||
call_credentials=None,
|
||||
insecure=False,
|
||||
compression=None,
|
||||
wait_for_ready=None,
|
||||
timeout=None,
|
||||
metadata=None):
|
||||
return grpc.experimental.unary_unary(
|
||||
request,
|
||||
target,
|
||||
'/auto.AutoAvgCostService/AutoAvgCost',
|
||||
auto__pb2.AutoAvgCostRequest.SerializeToString,
|
||||
auto__pb2.AutoAvgCostResponse.FromString,
|
||||
options,
|
||||
channel_credentials,
|
||||
insecure,
|
||||
call_credentials,
|
||||
compression,
|
||||
wait_for_ready,
|
||||
timeout,
|
||||
metadata,
|
||||
_registered_method=True)
|
||||
48
core/services/grpc/auto.py
Normal file
48
core/services/grpc/auto.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import grpc
|
||||
from google.protobuf.timestamp_pb2 import Timestamp
|
||||
from datetime import datetime
|
||||
|
||||
from config.env import env
|
||||
from core.generated import auto_pb2, auto_pb2_grpc
|
||||
|
||||
|
||||
def get_auto_avg_cost(
|
||||
brand,
|
||||
condition,
|
||||
model,
|
||||
complication,
|
||||
manufacture_date: datetime,
|
||||
distance_covered,
|
||||
color
|
||||
):
|
||||
# url = f"{env.str('RPC_IP')}:{env.str('RPC_PORT')}"
|
||||
# channel = grpc.insecure_channel(url)
|
||||
channel = grpc.insecure_channel("192.168.1.120:50051")
|
||||
stub = auto_pb2_grpc.AutoAvgCostServiceStub(channel)
|
||||
|
||||
ts = Timestamp()
|
||||
ts.FromDatetime(manufacture_date)
|
||||
|
||||
response = stub.AutoAvgCost(auto_pb2.AutoAvgCostRequest(
|
||||
brand=brand,
|
||||
condition=condition,
|
||||
model=model,
|
||||
complication=complication,
|
||||
manufacture_date=ts,
|
||||
distance_covered=distance_covered,
|
||||
color=color,
|
||||
))
|
||||
|
||||
return {
|
||||
"avg_cost": response.avg_cost,
|
||||
"ads": [
|
||||
{
|
||||
"id": ad.id,
|
||||
"title": ad.title,
|
||||
"price": ad.price,
|
||||
"model": ad.model,
|
||||
"images": [img.image for img in ad.images],
|
||||
}
|
||||
for ad in response.ads
|
||||
]
|
||||
}
|
||||
@@ -46,3 +46,7 @@ boto3
|
||||
# !NOTE: on-websocket
|
||||
# websockets
|
||||
# channels-redis
|
||||
|
||||
grpcio>=1.62.0
|
||||
grpcio-tools>=1.62.0
|
||||
protobuf>=4.25.0
|
||||
@@ -84,7 +84,7 @@ services:
|
||||
max-file: "5"
|
||||
|
||||
web:
|
||||
image: husanjon/sifatbaho:107
|
||||
image: husanjon/sifatbaho:124
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
@@ -129,7 +129,7 @@ services:
|
||||
max-file: "5"
|
||||
|
||||
celery:
|
||||
image: husanjon/sifatbaho:107
|
||||
image: husanjon/sifatbaho:124
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
|
||||
Reference in New Issue
Block a user