Compare commits
1 Commits
40a68ff47d
...
fix/evalua
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8207b750b8 |
@@ -2,26 +2,11 @@ import os
|
|||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
|
||||||
|
|
||||||
asgi_application = get_asgi_application()
|
asgi_application = get_asgi_application()
|
||||||
|
from config.env import env # noqa
|
||||||
|
|
||||||
from channels.routing import ProtocolTypeRouter, URLRouter # noqa
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", env("DJANGO_SETTINGS_MODULE"))
|
||||||
from django.urls import re_path # noqa
|
|
||||||
|
|
||||||
from core.apps.chat.consumers import ChatConsumer # noqa
|
|
||||||
from core.apps.chat.middlewares.auth import JWTAuthMiddlewareStack # noqa
|
|
||||||
|
|
||||||
websocket_urlpatterns = [
|
application = asgi_application
|
||||||
re_path(
|
|
||||||
r"^ws/chat/room/(?P<room_id>\d+)/$",
|
|
||||||
ChatConsumer.as_asgi(),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
application = ProtocolTypeRouter({
|
|
||||||
"http": asgi_application,
|
|
||||||
"websocket": JWTAuthMiddlewareStack(
|
|
||||||
URLRouter(websocket_urlpatterns)
|
|
||||||
),
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
MODULES = ["core.apps.shared", "core.apps.evaluation", "core.apps.payment", "core.apps.chat"]
|
MODULES = ["core.apps.shared", "core.apps.evaluation", "core.apps.payment"]
|
||||||
|
|||||||
@@ -112,33 +112,6 @@ PAGES = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"title": _("Tarix"),
|
|
||||||
"separator": True,
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"title": _("Avto baholash tarixi"),
|
|
||||||
"icon": "history",
|
|
||||||
"link": reverse_lazy("admin:evaluation_autoevaluationhistorymodel_changelist"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": _("Tezkor baholash tarixi"),
|
|
||||||
"icon": "manage_history",
|
|
||||||
"link": reverse_lazy("admin:evaluation_quickevaluationhistorymodel_changelist"),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": _("Chat"),
|
|
||||||
"separator": True,
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"title": _("Chat xabarlari"),
|
|
||||||
"icon": "chat",
|
|
||||||
"link": reverse_lazy("admin:chat_chatmessagemodel_changelist"),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"title": _("Ma'lumotnomalari"),
|
"title": _("Ma'lumotnomalari"),
|
||||||
"separator": True,
|
"separator": True,
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
REST_FRAMEWORK: Union[Any] = {
|
REST_FRAMEWORK: Union[Any] = {
|
||||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
"DEFAULT_AUTHENTICATION_CLASSES": ("rest_framework_simplejwt.authentication.JWTAuthentication",),
|
||||||
"rest_framework_simplejwt.authentication.JWTAuthentication",
|
|
||||||
"rest_framework.authentication.SessionAuthentication",
|
|
||||||
# "rest_framework.authentication.BaseAuthentication",
|
|
||||||
),
|
|
||||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||||
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
|
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
|
||||||
"DEFAULT_PAGINATION_CLASS": "django_core.paginations.CustomPagination",
|
"DEFAULT_PAGINATION_CLASS": "django_core.paginations.CustomPagination",
|
||||||
|
|||||||
@@ -148,18 +148,8 @@ AUTH_USER_MODEL = "accounts.User"
|
|||||||
CELERY_BROKER_URL = env("REDIS_URL")
|
CELERY_BROKER_URL = env("REDIS_URL")
|
||||||
CELERY_RESULT_BACKEND = env("REDIS_URL")
|
CELERY_RESULT_BACKEND = env("REDIS_URL")
|
||||||
|
|
||||||
CHANNEL_LAYERS = {
|
|
||||||
"default": {
|
|
||||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
|
||||||
"CONFIG": {
|
|
||||||
"hosts": [env("REDIS_URL")],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
ALLOWED_HOSTS += env("ALLOWED_HOSTS").split(",")
|
ALLOWED_HOSTS += env("ALLOWED_HOSTS").split(",")
|
||||||
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS").split(",")
|
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS").split(",")
|
||||||
SITE_URL = env.str("SITE_URL", default="http://localhost:8055")
|
|
||||||
|
|
||||||
|
|
||||||
MODELTRANSLATION_LANGUAGES = ("uz", "ru", "en")
|
MODELTRANSLATION_LANGUAGES = ("uz", "ru", "en")
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from config.env import env
|
|||||||
|
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
return HttpResponse("OK: #ea3f14058e4a7edbb94999d6287f396cd60e7305")
|
return HttpResponse("OK: #7bcf7bdc7f8b10357921efee0415dc6211137338")
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -22,7 +22,6 @@ urlpatterns = [
|
|||||||
path("api/", include("core.apps.shared.urls")),
|
path("api/", include("core.apps.shared.urls")),
|
||||||
path("api/v1/", include("core.apps.evaluation.urls")),
|
path("api/v1/", include("core.apps.evaluation.urls")),
|
||||||
path("api/v1/", include("core.apps.payment.urls")),
|
path("api/v1/", include("core.apps.payment.urls")),
|
||||||
path("api/v1/", include("core.apps.chat.urls")),
|
|
||||||
]
|
]
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from django.contrib.auth import admin
|
from django.contrib.auth import admin
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
from unfold.admin import ModelAdmin
|
from unfold.admin import ModelAdmin
|
||||||
from unfold.forms import AdminPasswordChangeForm # UserCreationForm,
|
from unfold.forms import AdminPasswordChangeForm # UserCreationForm,
|
||||||
from unfold.forms import UserChangeForm
|
from unfold.forms import UserChangeForm
|
||||||
@@ -11,7 +10,6 @@ class CustomUserAdmin(admin.UserAdmin, ModelAdmin):
|
|||||||
# add_form = UserCreationForm
|
# add_form = UserCreationForm
|
||||||
form = UserChangeForm
|
form = UserChangeForm
|
||||||
list_display = (
|
list_display = (
|
||||||
"display_avatar",
|
|
||||||
"first_name",
|
"first_name",
|
||||||
"last_name",
|
"last_name",
|
||||||
"phone",
|
"phone",
|
||||||
@@ -19,7 +17,7 @@ class CustomUserAdmin(admin.UserAdmin, ModelAdmin):
|
|||||||
)
|
)
|
||||||
search_fields = ("phone", "first_name", "last_name", "username")
|
search_fields = ("phone", "first_name", "last_name", "username")
|
||||||
autocomplete_fields = ["groups", "user_permissions"]
|
autocomplete_fields = ["groups", "user_permissions"]
|
||||||
fieldsets = ((None, {"fields": ("phone", "avatar",)}),) + (
|
fieldsets = ((None, {"fields": ("phone",)}),) + (
|
||||||
(None, {"fields": ("username", "password")}),
|
(None, {"fields": ("username", "password")}),
|
||||||
(_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
|
(_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
|
||||||
(
|
(
|
||||||
@@ -38,15 +36,6 @@ class CustomUserAdmin(admin.UserAdmin, ModelAdmin):
|
|||||||
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
|
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
|
||||||
)
|
)
|
||||||
|
|
||||||
def display_avatar(self, obj):
|
|
||||||
if obj.avatar:
|
|
||||||
return mark_safe(
|
|
||||||
f'<img src="{obj.avatar.url}" width="35" height="35" style="border-radius: 50%; object-fit: cover;" />'
|
|
||||||
)
|
|
||||||
return _("No Image")
|
|
||||||
|
|
||||||
display_avatar.short_description = _("Avatar")
|
|
||||||
|
|
||||||
|
|
||||||
class PermissionAdmin(ModelAdmin):
|
class PermissionAdmin(ModelAdmin):
|
||||||
list_display = ("name",)
|
list_display = ("name",)
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-03-17 12:32
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('accounts', '0002_alter_user_role'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='user',
|
|
||||||
name='avatar',
|
|
||||||
field=models.ImageField(blank=True, null=True, upload_to='avatars/'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -16,7 +16,6 @@ class User(auth_models.AbstractUser):
|
|||||||
choices=RoleChoice,
|
choices=RoleChoice,
|
||||||
default=RoleChoice.USER,
|
default=RoleChoice.USER,
|
||||||
)
|
)
|
||||||
avatar = models.ImageField(upload_to="avatars/", null=True, blank=True)
|
|
||||||
|
|
||||||
USERNAME_FIELD = "phone"
|
USERNAME_FIELD = "phone"
|
||||||
objects = UserManager()
|
objects = UserManager()
|
||||||
|
|||||||
@@ -19,6 +19,5 @@ class UserUpdateSerializer(serializers.ModelSerializer):
|
|||||||
model = get_user_model()
|
model = get_user_model()
|
||||||
fields = [
|
fields = [
|
||||||
"first_name",
|
"first_name",
|
||||||
"last_name",
|
"last_name"
|
||||||
"avatar"
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from django.contrib.auth import get_user_model
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_core import exceptions
|
from django_core import exceptions
|
||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from rest_framework import status, throttling, request, parsers
|
from rest_framework import status, throttling, request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.exceptions import PermissionDenied
|
from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
@@ -160,11 +160,6 @@ class ResetPasswordView(BaseViewSetMixin, GenericViewSet, UserService):
|
|||||||
@extend_schema(tags=["me"])
|
@extend_schema(tags=["me"])
|
||||||
class MeView(BaseViewSetMixin, GenericViewSet, UserService):
|
class MeView(BaseViewSetMixin, GenericViewSet, UserService):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
parser_classes = (
|
|
||||||
parsers.MultiPartParser,
|
|
||||||
parsers.FormParser,
|
|
||||||
parsers.JSONParser,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
match self.action:
|
match self.action:
|
||||||
@@ -183,8 +178,8 @@ class MeView(BaseViewSetMixin, GenericViewSet, UserService):
|
|||||||
def user_update(self, request):
|
def user_update(self, request):
|
||||||
ser = self.get_serializer(instance=request.user, data=request.data, partial=True)
|
ser = self.get_serializer(instance=request.user, data=request.data, partial=True)
|
||||||
ser.is_valid(raise_exception=True)
|
ser.is_valid(raise_exception=True)
|
||||||
data = ser.save()
|
ser.save()
|
||||||
return Response(UserSerializer(data).data)
|
return Response({"detail": _("Malumotlar yangilandi")})
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["change-password"], description="Parolni o'zgartirish uchun")
|
@extend_schema(tags=["change-password"], description="Parolni o'zgartirish uchun")
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from unfold.admin import ModelAdmin
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(ChatmessageModel)
|
|
||||||
class ChatmessageAdmin(ModelAdmin):
|
|
||||||
list_display = (
|
|
||||||
"id",
|
|
||||||
"room",
|
|
||||||
"message_type",
|
|
||||||
"sender",
|
|
||||||
"short_text",
|
|
||||||
"is_read",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
list_filter = ("message_type", "is_read", "created_at")
|
|
||||||
search_fields = (
|
|
||||||
"text",
|
|
||||||
"sender__phone",
|
|
||||||
"sender__first_name",
|
|
||||||
"sender__last_name",
|
|
||||||
)
|
|
||||||
readonly_fields = ("created_at",)
|
|
||||||
autocomplete_fields = ("sender",)
|
|
||||||
ordering = ("-created_at",)
|
|
||||||
fieldsets = (
|
|
||||||
(
|
|
||||||
_("Xabar"),
|
|
||||||
{
|
|
||||||
"fields": ("room", "sender", "message_type", "text", "file", "is_read"),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
_("Tizim"),
|
|
||||||
{
|
|
||||||
"classes": ("collapse",),
|
|
||||||
"fields": ("created_at",),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def has_change_permission(self, request, obj=None):
|
|
||||||
return False
|
|
||||||
|
|
||||||
@admin.display(description=_("Xabar"))
|
|
||||||
def short_text(self, obj):
|
|
||||||
if not obj.text:
|
|
||||||
return f"[{obj.message_type}]"
|
|
||||||
return obj.text[:60] + "..." if len(obj.text) > 60 else obj.text
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(ChatroomModel)
|
|
||||||
class ChatroomAdmin(ModelAdmin):
|
|
||||||
list_display = (
|
|
||||||
"id",
|
|
||||||
"__str__",
|
|
||||||
"type",
|
|
||||||
"auto_evaluation",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
list_filter = ("type",)
|
|
||||||
search_fields = ("auto_evaluation__id",)
|
|
||||||
autocomplete_fields = ("auto_evaluation",)
|
|
||||||
filter_horizontal = ("members",)
|
|
||||||
readonly_fields = ("created_at", "updated_at")
|
|
||||||
fieldsets = (
|
|
||||||
(
|
|
||||||
_("Xona"),
|
|
||||||
{
|
|
||||||
"fields": ("type", "auto_evaluation", "members"),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
_("Tizim"),
|
|
||||||
{
|
|
||||||
"classes": ("collapse",),
|
|
||||||
"fields": ("created_at", "updated_at"),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleConfig(AppConfig):
|
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
|
||||||
name = "core.apps.chat"
|
|
||||||
|
|
||||||
def ready(self):
|
|
||||||
import core.apps.chat.signals # noqa
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class RoomType(models.TextChoices):
|
|
||||||
AUTO_EVALUATION = "auto_evaluation", _("AutoEvaluation xonasi")
|
|
||||||
DIRECT = "direct", _("To'g'ridan-to'g'ri")
|
|
||||||
|
|
||||||
|
|
||||||
class MessageType(models.TextChoices):
|
|
||||||
TEXT = "text", _("Matn")
|
|
||||||
IMAGE = "image", _("Rasm")
|
|
||||||
VIDEO = "video", _("Video")
|
|
||||||
VOICE = "voice", _("Ovoz")
|
|
||||||
FILE = "file", _("Fayl")
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import ChatConsumer # noqa
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
import json
|
|
||||||
|
|
||||||
from channels.db import database_sync_to_async
|
|
||||||
from channels.generic.websocket import AsyncWebsocketConsumer
|
|
||||||
from django.contrib.auth.models import AnonymousUser
|
|
||||||
|
|
||||||
|
|
||||||
class ChatConsumer(AsyncWebsocketConsumer):
|
|
||||||
"""
|
|
||||||
Xona asosidagi chat consumer.
|
|
||||||
Ulanish: ws://host/ws/chat/room/{room_id}/?token=<jwt>
|
|
||||||
|
|
||||||
Matn xabari yuborish:
|
|
||||||
{ "message_type": "text", "text": "Salom" }
|
|
||||||
|
|
||||||
Fayl xabari (oldin REST orqali yuklab, keyin URL yuborish):
|
|
||||||
{ "message_type": "image", "file_url": "https://...", "text": "caption (ixtiyoriy)" }
|
|
||||||
"""
|
|
||||||
|
|
||||||
async def connect(self):
|
|
||||||
user = self.scope.get("user")
|
|
||||||
if not user or isinstance(user, AnonymousUser):
|
|
||||||
await self.close(code=4001)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.room_id = self.scope["url_route"]["kwargs"]["room_id"]
|
|
||||||
self.room_group = f"chat_room_{self.room_id}"
|
|
||||||
|
|
||||||
await self.channel_layer.group_add(self.room_group, self.channel_name)
|
|
||||||
await self.accept()
|
|
||||||
|
|
||||||
async def disconnect(self, close_code):
|
|
||||||
if hasattr(self, "room_group"):
|
|
||||||
await self.channel_layer.group_discard(self.room_group, self.channel_name)
|
|
||||||
|
|
||||||
async def receive(self, text_data):
|
|
||||||
user = self.scope.get("user")
|
|
||||||
if not user or isinstance(user, AnonymousUser):
|
|
||||||
await self.close(code=4001)
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
data = json.loads(text_data)
|
|
||||||
except (json.JSONDecodeError, ValueError):
|
|
||||||
await self.send(text_data=json.dumps({"error": "Noto'g'ri format."}))
|
|
||||||
return
|
|
||||||
|
|
||||||
message_type = data.get("message_type", "text")
|
|
||||||
text = (data.get("text") or "").strip()
|
|
||||||
|
|
||||||
# Matn xabari uchun text majburiy
|
|
||||||
if message_type == "text" and not text:
|
|
||||||
await self.send(text_data=json.dumps({"error": "Matn bo'sh bo'lishi mumkin emas."}))
|
|
||||||
return
|
|
||||||
|
|
||||||
# WS orqali faqat matn + caption saqlanadi.
|
|
||||||
# Fayl yuklash uchun REST /chat/messages/ POST ishlatiladi.
|
|
||||||
if message_type != "text":
|
|
||||||
await self.send(
|
|
||||||
text_data=json.dumps(
|
|
||||||
{"error": "Fayl xabarlarni yuklash uchun REST API dan foydalaning."}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
# DB ga saqlash — post_save signal WS ga broadcast qiladi
|
|
||||||
await self._save_message(user, text)
|
|
||||||
|
|
||||||
async def chat_message(self, event):
|
|
||||||
await self.send(
|
|
||||||
text_data=json.dumps(
|
|
||||||
{
|
|
||||||
"id": event["id"],
|
|
||||||
"message_type": event["message_type"],
|
|
||||||
"text": event["text"],
|
|
||||||
"file_url": event["file_url"],
|
|
||||||
"sender": event["sender"],
|
|
||||||
"created_at": event["created_at"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@database_sync_to_async
|
|
||||||
def _save_message(self, user, text):
|
|
||||||
from core.apps.chat.models import ChatmessageModel
|
|
||||||
|
|
||||||
msg = ChatmessageModel.objects.create(
|
|
||||||
room_id=self.room_id,
|
|
||||||
sender=user,
|
|
||||||
message_type="text",
|
|
||||||
text=text,
|
|
||||||
)
|
|
||||||
full_name = user.get_full_name().strip() or str(user.phone)
|
|
||||||
return {
|
|
||||||
"id": msg.id,
|
|
||||||
"message_type": msg.message_type,
|
|
||||||
"text": msg.text,
|
|
||||||
"file_url": None,
|
|
||||||
"sender": {
|
|
||||||
"id": user.id,
|
|
||||||
"full_name": full_name,
|
|
||||||
"role": user.role,
|
|
||||||
},
|
|
||||||
"created_at": msg.created_at.isoformat(),
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
from django_filters import rest_framework as filters
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
class ChatmessageFilter(filters.FilterSet):
|
|
||||||
room = filters.NumberFilter(field_name="room_id", lookup_expr="exact")
|
|
||||||
message_type = filters.CharFilter(field_name="message_type", lookup_expr="exact")
|
|
||||||
is_read = filters.BooleanFilter(field_name="is_read")
|
|
||||||
created_from = filters.DateTimeFilter(field_name="created_at", lookup_expr="gte")
|
|
||||||
created_to = filters.DateTimeFilter(field_name="created_at", lookup_expr="lte")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatmessageModel
|
|
||||||
fields = [
|
|
||||||
"room",
|
|
||||||
"message_type",
|
|
||||||
"is_read",
|
|
||||||
"created_from",
|
|
||||||
"created_to",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ChatroomFilter(filters.FilterSet):
|
|
||||||
type = filters.CharFilter(field_name="type", lookup_expr="exact")
|
|
||||||
auto_evaluation = filters.NumberFilter(field_name="auto_evaluation_id", lookup_expr="exact")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatroomModel
|
|
||||||
fields = [
|
|
||||||
"type",
|
|
||||||
"auto_evaluation",
|
|
||||||
]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
from django import forms
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
class ChatmessageForm(forms.ModelForm):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatmessageModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class ChatroomForm(forms.ModelForm):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatroomModel
|
|
||||||
fields = "__all__"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .auth import * # noqa
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import traceback
|
|
||||||
from urllib.parse import parse_qs
|
|
||||||
|
|
||||||
from channels.auth import AuthMiddlewareStack
|
|
||||||
from channels.db import database_sync_to_async
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from django.contrib.auth.models import AnonymousUser
|
|
||||||
from django.db import close_old_connections
|
|
||||||
from jwt import DecodeError, ExpiredSignatureError, InvalidSignatureError
|
|
||||||
from jwt import decode as jwt_decode
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
|
|
||||||
class JWTAuthMiddleware:
|
|
||||||
def __init__(self, app):
|
|
||||||
self.app = app
|
|
||||||
|
|
||||||
async def __call__(self, scope, receive, send):
|
|
||||||
close_old_connections()
|
|
||||||
try:
|
|
||||||
if jwt_token_list := parse_qs(scope["query_string"].decode("utf8")).get(
|
|
||||||
"token", None
|
|
||||||
):
|
|
||||||
jwt_token = jwt_token_list[0]
|
|
||||||
jwt_payload = self.get_payload(jwt_token)
|
|
||||||
user_credentials = self.get_user_credentials(jwt_payload)
|
|
||||||
user = await self.get_logged_in_user(user_credentials)
|
|
||||||
scope["user"] = user
|
|
||||||
else:
|
|
||||||
scope["user"] = AnonymousUser()
|
|
||||||
except (
|
|
||||||
InvalidSignatureError,
|
|
||||||
KeyError,
|
|
||||||
ExpiredSignatureError,
|
|
||||||
DecodeError,
|
|
||||||
):
|
|
||||||
traceback.print_exc()
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
scope["user"] = AnonymousUser()
|
|
||||||
return await self.app(scope, receive, send)
|
|
||||||
|
|
||||||
def get_payload(self, jwt_token):
|
|
||||||
payload = jwt_decode(jwt_token, settings.SECRET_KEY, algorithms=["HS256"])
|
|
||||||
return payload
|
|
||||||
|
|
||||||
def get_user_credentials(self, payload):
|
|
||||||
"""
|
|
||||||
method to get user credentials from jwt token payload.
|
|
||||||
defaults to user id.
|
|
||||||
"""
|
|
||||||
user_id = payload["user_id"]
|
|
||||||
return user_id
|
|
||||||
|
|
||||||
async def get_logged_in_user(self, user_id):
|
|
||||||
user = await self.get_user(user_id)
|
|
||||||
return user
|
|
||||||
|
|
||||||
@database_sync_to_async
|
|
||||||
def get_user(self, user_id):
|
|
||||||
try:
|
|
||||||
return User.objects.get(id=user_id)
|
|
||||||
except User.DoesNotExist:
|
|
||||||
return AnonymousUser()
|
|
||||||
|
|
||||||
|
|
||||||
def JWTAuthMiddlewareStack(app):
|
|
||||||
return JWTAuthMiddleware(AuthMiddlewareStack(app))
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-04-02 14:22
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0026_alter_autoevaluationmodel_form_ownership_and_more'),
|
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='ChatmessageModel',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('text', models.TextField(verbose_name='text')),
|
|
||||||
('is_read', models.BooleanField(db_index=True, default=False, verbose_name='is read')),
|
|
||||||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
|
|
||||||
('auto_evaluation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_messages', to='evaluation.autoevaluationmodel', verbose_name='auto evaluation')),
|
|
||||||
('sender', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='chat_messages', to=settings.AUTH_USER_MODEL, verbose_name='sender')),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'Chat Message',
|
|
||||||
'verbose_name_plural': 'Chat Messages',
|
|
||||||
'db_table': 'ChatMessage',
|
|
||||||
'ordering': ['created_at'],
|
|
||||||
'indexes': [models.Index(fields=['auto_evaluation_id', 'created_at'], name='chat_eval_date_idx'), models.Index(fields=['auto_evaluation_id', 'is_read'], name='chat_eval_read_idx')],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
from django.conf import settings
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
import core.apps.chat.models.chat
|
|
||||||
|
|
||||||
|
|
||||||
def delete_old_messages(apps, schema_editor):
|
|
||||||
"""Eski xabarlarni o'chirish — room FK bilan mos kelmaydi."""
|
|
||||||
ChatmessageModel = apps.get_model("chat", "ChatmessageModel")
|
|
||||||
ChatmessageModel.objects.all().delete()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("chat", "0001_initial_chat_message"),
|
|
||||||
("evaluation", "0026_alter_autoevaluationmodel_form_ownership_and_more"),
|
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
# 1. ChatroomModel yaratish
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="ChatroomModel",
|
|
||||||
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)),
|
|
||||||
(
|
|
||||||
"type",
|
|
||||||
models.CharField(
|
|
||||||
choices=[
|
|
||||||
("auto_evaluation", "AutoEvaluation xonasi"),
|
|
||||||
("direct", "To\u2018g\u2018ridan-to\u2018g\u2018ri"),
|
|
||||||
],
|
|
||||||
db_index=True,
|
|
||||||
default="auto_evaluation",
|
|
||||||
max_length=20,
|
|
||||||
verbose_name="type",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"auto_evaluation",
|
|
||||||
models.OneToOneField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="chat_room",
|
|
||||||
to="evaluation.autoevaluationmodel",
|
|
||||||
verbose_name="auto evaluation",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"members",
|
|
||||||
models.ManyToManyField(
|
|
||||||
blank=True,
|
|
||||||
related_name="chat_rooms",
|
|
||||||
to=settings.AUTH_USER_MODEL,
|
|
||||||
verbose_name="members",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
"verbose_name": "Chat Xona",
|
|
||||||
"verbose_name_plural": "Chat Xonalar",
|
|
||||||
"db_table": "ChatRoom",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
# 2. Eski xabarlarni o'chirish (room FKsiz migratsiya mumkin emas)
|
|
||||||
migrations.RunPython(delete_old_messages, migrations.RunPython.noop),
|
|
||||||
# 3. Eski indexlarni o'chirish
|
|
||||||
migrations.RemoveIndex(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="chat_eval_date_idx",
|
|
||||||
),
|
|
||||||
migrations.RemoveIndex(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="chat_eval_read_idx",
|
|
||||||
),
|
|
||||||
# 4. auto_evaluation FK o'chirish
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="auto_evaluation",
|
|
||||||
),
|
|
||||||
# 5. room FK qo'shish
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="room",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="messages",
|
|
||||||
to="chat.chatroommodel",
|
|
||||||
verbose_name="room",
|
|
||||||
null=True,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
# 6. room ni non-null qilish
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="room",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
on_delete=django.db.models.deletion.CASCADE,
|
|
||||||
related_name="messages",
|
|
||||||
to="chat.chatroommodel",
|
|
||||||
verbose_name="room",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
# 7. message_type qo'shish
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="message_type",
|
|
||||||
field=models.CharField(
|
|
||||||
choices=[
|
|
||||||
("text", "Matn"),
|
|
||||||
("image", "Rasm"),
|
|
||||||
("video", "Video"),
|
|
||||||
("voice", "Ovoz"),
|
|
||||||
("file", "Fayl"),
|
|
||||||
],
|
|
||||||
db_index=True,
|
|
||||||
default="text",
|
|
||||||
max_length=10,
|
|
||||||
verbose_name="message type",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
# 8. text ni nullable qilish
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="text",
|
|
||||||
field=models.TextField(blank=True, null=True, verbose_name="text"),
|
|
||||||
),
|
|
||||||
# 9. file field qo'shish
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
name="file",
|
|
||||||
field=models.FileField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
upload_to=core.apps.chat.models.chat.chat_file_upload_path,
|
|
||||||
verbose_name="file",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
# 10. Yangi indexlar
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
index=models.Index(fields=["room_id", "created_at"], name="chat_room_date_idx"),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name="chatmessagemodel",
|
|
||||||
index=models.Index(fields=["room_id", "is_read"], name="chat_room_read_idx"),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from django_core.models import AbstractBaseModel
|
|
||||||
from model_bakery import baker
|
|
||||||
|
|
||||||
from core.apps.chat.choices.chat import MessageType, RoomType
|
|
||||||
|
|
||||||
|
|
||||||
def chat_file_upload_path(instance, filename):
|
|
||||||
return f"chat/{instance.message_type}/{filename}"
|
|
||||||
|
|
||||||
|
|
||||||
class ChatroomModel(AbstractBaseModel):
|
|
||||||
type = models.CharField(
|
|
||||||
verbose_name=_("type"),
|
|
||||||
max_length=20,
|
|
||||||
choices=RoomType.choices,
|
|
||||||
default=RoomType.AUTO_EVALUATION,
|
|
||||||
db_index=True,
|
|
||||||
)
|
|
||||||
auto_evaluation = models.OneToOneField(
|
|
||||||
"evaluation.AutoEvaluationModel",
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
related_name="chat_room",
|
|
||||||
verbose_name=_("auto evaluation"),
|
|
||||||
)
|
|
||||||
members = models.ManyToManyField(
|
|
||||||
"accounts.User",
|
|
||||||
blank=True,
|
|
||||||
related_name="chat_rooms",
|
|
||||||
verbose_name=_("members"),
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
if self.type == RoomType.AUTO_EVALUATION and self.auto_evaluation_id:
|
|
||||||
return f"AutoEval #{self.auto_evaluation_id} xonasi"
|
|
||||||
return f"Direct xona #{self.pk}"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _baker(cls):
|
|
||||||
return baker.make(cls)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = "ChatRoom"
|
|
||||||
verbose_name = _("Chat Xona")
|
|
||||||
verbose_name_plural = _("Chat Xonalar")
|
|
||||||
|
|
||||||
|
|
||||||
class ChatmessageModel(models.Model):
|
|
||||||
room = models.ForeignKey(
|
|
||||||
ChatroomModel,
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name="messages",
|
|
||||||
verbose_name=_("room"),
|
|
||||||
)
|
|
||||||
sender = models.ForeignKey(
|
|
||||||
"accounts.User",
|
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
null=True,
|
|
||||||
related_name="chat_messages",
|
|
||||||
verbose_name=_("sender"),
|
|
||||||
)
|
|
||||||
message_type = models.CharField(
|
|
||||||
verbose_name=_("message type"),
|
|
||||||
max_length=10,
|
|
||||||
choices=MessageType.choices,
|
|
||||||
default=MessageType.TEXT,
|
|
||||||
db_index=True,
|
|
||||||
)
|
|
||||||
text = models.TextField(verbose_name=_("text"), null=True, blank=True)
|
|
||||||
file = models.FileField(
|
|
||||||
verbose_name=_("file"),
|
|
||||||
upload_to=chat_file_upload_path,
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
)
|
|
||||||
is_read = models.BooleanField(
|
|
||||||
verbose_name=_("is read"),
|
|
||||||
default=False,
|
|
||||||
db_index=True,
|
|
||||||
)
|
|
||||||
created_at = models.DateTimeField(
|
|
||||||
verbose_name=_("created at"),
|
|
||||||
auto_now_add=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"#{self.pk} — {self.sender}"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _baker(cls):
|
|
||||||
return baker.make(cls)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = "ChatMessage"
|
|
||||||
verbose_name = _("Chat Xabar")
|
|
||||||
verbose_name_plural = _("Chat Xabarlar")
|
|
||||||
ordering = ["created_at"]
|
|
||||||
indexes = [
|
|
||||||
models.Index(
|
|
||||||
fields=["room_id", "created_at"],
|
|
||||||
name="chat_room_date_idx",
|
|
||||||
),
|
|
||||||
models.Index(
|
|
||||||
fields=["room_id", "is_read"],
|
|
||||||
name="chat_room_read_idx",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
from rest_framework import permissions
|
|
||||||
|
|
||||||
|
|
||||||
class ChatmessagePermission(permissions.BasePermission):
|
|
||||||
|
|
||||||
def __init__(self) -> None: ...
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class ChatroomPermission(permissions.BasePermission):
|
|
||||||
|
|
||||||
def __init__(self) -> None: ...
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
|
||||||
return True
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel
|
|
||||||
|
|
||||||
|
|
||||||
class BaseChatmessageSerializer(serializers.ModelSerializer):
|
|
||||||
sender = serializers.SerializerMethodField()
|
|
||||||
file_url = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_sender(self, obj):
|
|
||||||
if obj.sender is None:
|
|
||||||
return None
|
|
||||||
full_name = obj.sender.get_full_name().strip()
|
|
||||||
if not full_name:
|
|
||||||
full_name = str(obj.sender.phone)
|
|
||||||
return {
|
|
||||||
"id": obj.sender.id,
|
|
||||||
"full_name": full_name,
|
|
||||||
"role": obj.sender.role,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_file_url(self, obj):
|
|
||||||
if not obj.file:
|
|
||||||
return None
|
|
||||||
request = self.context.get("request")
|
|
||||||
if request:
|
|
||||||
return request.build_absolute_uri(obj.file.url)
|
|
||||||
return obj.file.url
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatmessageModel
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"room",
|
|
||||||
"sender",
|
|
||||||
"message_type",
|
|
||||||
"text",
|
|
||||||
"file_url",
|
|
||||||
"is_read",
|
|
||||||
"created_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ListChatmessageSerializer(BaseChatmessageSerializer):
|
|
||||||
class Meta(BaseChatmessageSerializer.Meta): ...
|
|
||||||
|
|
||||||
|
|
||||||
class RetrieveChatmessageSerializer(BaseChatmessageSerializer):
|
|
||||||
class Meta(BaseChatmessageSerializer.Meta): ...
|
|
||||||
|
|
||||||
|
|
||||||
class CreateChatmessageSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = ChatmessageModel
|
|
||||||
fields = [
|
|
||||||
"room",
|
|
||||||
"message_type",
|
|
||||||
"text",
|
|
||||||
"file",
|
|
||||||
]
|
|
||||||
|
|
||||||
def validate(self, attrs):
|
|
||||||
message_type = attrs.get("message_type", "text")
|
|
||||||
text = attrs.get("text", "").strip() if attrs.get("text") else ""
|
|
||||||
file = attrs.get("file")
|
|
||||||
|
|
||||||
if message_type == "text" and not text:
|
|
||||||
raise serializers.ValidationError({"text": "Matn xabari uchun text majburiy."})
|
|
||||||
if message_type != "text" and not file:
|
|
||||||
raise serializers.ValidationError({"file": f"{message_type} xabari uchun fayl majburiy."})
|
|
||||||
return attrs
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
|
||||||
validated_data["sender"] = self.context["request"].user
|
|
||||||
return super().create(validated_data)
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
class MemberSerializer(serializers.Serializer):
|
|
||||||
id = serializers.IntegerField()
|
|
||||||
full_name = serializers.SerializerMethodField()
|
|
||||||
role = serializers.CharField()
|
|
||||||
|
|
||||||
def get_full_name(self, obj):
|
|
||||||
name = obj.get_full_name().strip()
|
|
||||||
return name if name else str(obj.phone)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseChatroomSerializer(serializers.ModelSerializer):
|
|
||||||
members = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_members(self, obj):
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"id": u.id,
|
|
||||||
"full_name": (u.get_full_name().strip() or str(u.phone)),
|
|
||||||
"role": u.role,
|
|
||||||
}
|
|
||||||
for u in obj.members.only("id", "first_name", "last_name", "phone", "role")
|
|
||||||
]
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatroomModel
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"type",
|
|
||||||
"auto_evaluation",
|
|
||||||
"members",
|
|
||||||
"created_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ListChatroomSerializer(BaseChatroomSerializer):
|
|
||||||
class Meta(BaseChatroomSerializer.Meta): ...
|
|
||||||
|
|
||||||
|
|
||||||
class RetrieveChatroomSerializer(BaseChatroomSerializer):
|
|
||||||
class Meta(BaseChatroomSerializer.Meta): ...
|
|
||||||
|
|
||||||
|
|
||||||
class CreateChatroomSerializer(serializers.ModelSerializer):
|
|
||||||
type = serializers.ChoiceField(
|
|
||||||
choices=["auto_evaluation", "direct"],
|
|
||||||
required=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ChatroomModel
|
|
||||||
fields = [
|
|
||||||
"type",
|
|
||||||
"auto_evaluation",
|
|
||||||
"members",
|
|
||||||
]
|
|
||||||
|
|
||||||
def validate(self, attrs):
|
|
||||||
room_type = attrs.get("type")
|
|
||||||
if room_type == "auto_evaluation" and not attrs.get("auto_evaluation"):
|
|
||||||
raise serializers.ValidationError(
|
|
||||||
{"auto_evaluation": "auto_evaluation turi uchun AutoEvaluation majburiy."}
|
|
||||||
)
|
|
||||||
return attrs
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from .ChatMessage import * # noqa
|
|
||||||
from .ChatRoom import * # noqa
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
from asgiref.sync import async_to_sync
|
|
||||||
from channels.layers import get_channel_layer
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db.models.signals import post_save
|
|
||||||
from django.dispatch import receiver
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=ChatmessageModel)
|
|
||||||
def broadcast_new_message(sender, instance, created, **kwargs):
|
|
||||||
"""Yangi xabar saqlanganda xonadagi barcha WS ulanishlariga yuboradi."""
|
|
||||||
if not created:
|
|
||||||
return
|
|
||||||
|
|
||||||
channel_layer = get_channel_layer()
|
|
||||||
if channel_layer is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
sender_obj = instance.sender
|
|
||||||
if sender_obj:
|
|
||||||
full_name = sender_obj.get_full_name().strip() or str(sender_obj.phone)
|
|
||||||
sender_data = {
|
|
||||||
"id": sender_obj.id,
|
|
||||||
"full_name": full_name,
|
|
||||||
"role": sender_obj.role,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
sender_data = None
|
|
||||||
|
|
||||||
site_url = getattr(settings, "SITE_URL", "").rstrip("/")
|
|
||||||
file_url = (site_url + instance.file.url) if instance.file else None
|
|
||||||
|
|
||||||
async_to_sync(channel_layer.group_send)(
|
|
||||||
f"chat_room_{instance.room_id}",
|
|
||||||
{
|
|
||||||
"type": "chat_message",
|
|
||||||
"id": instance.id,
|
|
||||||
"message_type": instance.message_type,
|
|
||||||
"text": instance.text,
|
|
||||||
"file_url": file_url,
|
|
||||||
"sender": sender_data,
|
|
||||||
"created_at": instance.created_at.isoformat(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender="evaluation.AutoEvaluationModel")
|
|
||||||
def auto_create_chatroom(sender, instance, created, **kwargs):
|
|
||||||
"""AutoEvaluation yaratilganda avtomatik chat xonasi ochiladi."""
|
|
||||||
if created:
|
|
||||||
ChatroomModel.objects.get_or_create(
|
|
||||||
auto_evaluation=instance,
|
|
||||||
defaults={"type": "auto_evaluation"},
|
|
||||||
)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from .test_ChatMessage import * # noqa
|
|
||||||
from .test_ChatRoom import * # noqa
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from django.urls import reverse
|
|
||||||
from rest_framework.test import APIClient
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def instance(db):
|
|
||||||
return ChatmessageModel._baker()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def api_client(instance):
|
|
||||||
from model_bakery import baker
|
|
||||||
user = instance.sender or baker.make("accounts.User")
|
|
||||||
if not instance.sender:
|
|
||||||
instance.sender = user
|
|
||||||
instance.save()
|
|
||||||
|
|
||||||
# ensure the sender is a member of the room (just in case)
|
|
||||||
if instance.room:
|
|
||||||
instance.room.members.add(user)
|
|
||||||
|
|
||||||
client = APIClient()
|
|
||||||
client.force_authenticate(user=user)
|
|
||||||
return client, instance
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def data(api_client):
|
|
||||||
client, instance = api_client
|
|
||||||
return (
|
|
||||||
{
|
|
||||||
"list": reverse("chat-messages-list"),
|
|
||||||
"retrieve": reverse("chat-messages-detail", kwargs={"pk": instance.pk}),
|
|
||||||
"retrieve-not-found": reverse("chat-messages-detail", kwargs={"pk": 1000}),
|
|
||||||
},
|
|
||||||
client,
|
|
||||||
instance,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_list(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["list"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve_not_found(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve-not-found"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert data_resp["status"] is False
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_create(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.post(urls["list"], data={"name": "test"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 201
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_update(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_partial_update():
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_destroy(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.delete(urls["retrieve"])
|
|
||||||
# assert response.status_code == 204
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from django.urls import reverse
|
|
||||||
from rest_framework.test import APIClient
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def instance(db):
|
|
||||||
return ChatroomModel._baker()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def api_client(instance):
|
|
||||||
from model_bakery import baker
|
|
||||||
user = baker.make("accounts.User")
|
|
||||||
instance.members.add(user)
|
|
||||||
client = APIClient()
|
|
||||||
client.force_authenticate(user=user)
|
|
||||||
return client, instance
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def data(api_client):
|
|
||||||
client, instance = api_client
|
|
||||||
return (
|
|
||||||
{
|
|
||||||
"list": reverse("chat-rooms-list"),
|
|
||||||
"retrieve": reverse("chat-rooms-detail", kwargs={"pk": instance.pk}),
|
|
||||||
"retrieve-not-found": reverse("chat-rooms-detail", kwargs={"pk": 1000}),
|
|
||||||
},
|
|
||||||
client,
|
|
||||||
instance,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_list(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["list"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve_not_found(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve-not-found"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert data_resp["status"] is False
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_create(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.post(urls["list"], data={"name": "test"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 201
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_update(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_partial_update():
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_destroy(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.delete(urls["retrieve"])
|
|
||||||
# assert response.status_code == 204
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
from modeltranslation.translator import TranslationOptions, register
|
|
||||||
|
|
||||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
|
||||||
|
|
||||||
|
|
||||||
@register(ChatmessageModel)
|
|
||||||
class ChatmessageTranslation(TranslationOptions):
|
|
||||||
fields = []
|
|
||||||
|
|
||||||
|
|
||||||
@register(ChatroomModel)
|
|
||||||
class ChatroomTranslation(TranslationOptions):
|
|
||||||
fields = []
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
from django.urls import include, path
|
|
||||||
from rest_framework.routers import DefaultRouter
|
|
||||||
|
|
||||||
from .views import ChatmessageView, ChatRoomView
|
|
||||||
|
|
||||||
router = DefaultRouter()
|
|
||||||
router.register("rooms", ChatRoomView, basename="chat-rooms")
|
|
||||||
router.register("messages", ChatmessageView, basename="chat-messages")
|
|
||||||
urlpatterns = [path("", include(router.urls))]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# from django.core.exceptions import ValidationError
|
|
||||||
|
|
||||||
|
|
||||||
class ChatmessageValidator:
|
|
||||||
def __init__(self): ...
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class ChatroomValidator:
|
|
||||||
def __init__(self): ...
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
return True
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .chat import * # noqa
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
from django_core.mixins import BaseViewSetMixin
|
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
|
||||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
|
||||||
from rest_framework.decorators import action
|
|
||||||
from rest_framework.filters import OrderingFilter
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.viewsets import ModelViewSet
|
|
||||||
|
|
||||||
from core.apps.chat.filters.chat import ChatmessageFilter, ChatroomFilter
|
|
||||||
from core.apps.chat.models import ChatmessageModel, ChatroomModel
|
|
||||||
from core.apps.chat.serializers.chat import (
|
|
||||||
CreateChatmessageSerializer,
|
|
||||||
CreateChatroomSerializer,
|
|
||||||
ListChatmessageSerializer,
|
|
||||||
ListChatroomSerializer,
|
|
||||||
RetrieveChatmessageSerializer,
|
|
||||||
RetrieveChatroomSerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["Chat"],
|
|
||||||
parameters=[
|
|
||||||
OpenApiParameter("room", int, description="Xona ID bo'yicha filter"),
|
|
||||||
OpenApiParameter("message_type", str, description="Xabar turi: text, image, video, voice, file"),
|
|
||||||
OpenApiParameter("is_read", bool, description="O'qilgan/o'qilmagan"),
|
|
||||||
OpenApiParameter("created_from", str, description="Boshlanish sanasi (ISO 8601)"),
|
|
||||||
OpenApiParameter("created_to", str, description="Tugash sanasi (ISO 8601)"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
class ChatmessageView(BaseViewSetMixin, ModelViewSet):
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
parser_classes_for_create = None # multipart + json qo'llab-quvvatlanadi
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, OrderingFilter]
|
|
||||||
filterset_class = ChatmessageFilter
|
|
||||||
ordering_fields = ["created_at"]
|
|
||||||
ordering = ["created_at"]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
action_permission_classes = {}
|
|
||||||
action_serializer_class = {
|
|
||||||
"list": ListChatmessageSerializer,
|
|
||||||
"retrieve": RetrieveChatmessageSerializer,
|
|
||||||
"create": CreateChatmessageSerializer,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_serializer_class(self):
|
|
||||||
return self.action_serializer_class.get(self.action, ListChatmessageSerializer)
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return (
|
|
||||||
ChatmessageModel.objects.select_related("sender")
|
|
||||||
.only(
|
|
||||||
"id",
|
|
||||||
"room_id",
|
|
||||||
"message_type",
|
|
||||||
"text",
|
|
||||||
"file",
|
|
||||||
"is_read",
|
|
||||||
"created_at",
|
|
||||||
"sender__id",
|
|
||||||
"sender__first_name",
|
|
||||||
"sender__last_name",
|
|
||||||
"sender__phone",
|
|
||||||
"sender__role",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
|
||||||
results = list(queryset)
|
|
||||||
serializer = self.get_serializer(results, many=True)
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"count": len(results),
|
|
||||||
"next": None,
|
|
||||||
"previous": None,
|
|
||||||
"results": serializer.data,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
@extend_schema(description="Xabarlarni o'qilgan deb belgilash")
|
|
||||||
@action(detail=False, methods=["post"], url_path="mark-read")
|
|
||||||
def mark_read(self, request):
|
|
||||||
"""
|
|
||||||
Berilgan xona uchun barcha o'qilmagan xabarlarni o'qilgan qiladi.
|
|
||||||
Body: { "room": <id> }
|
|
||||||
"""
|
|
||||||
room_id = request.data.get("room")
|
|
||||||
if not room_id:
|
|
||||||
return Response({"detail": "room majburiy."}, status=400)
|
|
||||||
|
|
||||||
updated = (
|
|
||||||
ChatmessageModel.objects.filter(room_id=room_id, is_read=False)
|
|
||||||
.exclude(sender=request.user)
|
|
||||||
.update(is_read=True)
|
|
||||||
)
|
|
||||||
return Response({"updated": updated})
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["ChatRoom"],
|
|
||||||
parameters=[
|
|
||||||
OpenApiParameter("type", str, description="Xona turi: auto_evaluation, direct"),
|
|
||||||
OpenApiParameter("auto_evaluation", int, description="AutoEvaluation ID"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
class ChatRoomView(BaseViewSetMixin, ModelViewSet):
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend]
|
|
||||||
filterset_class = ChatroomFilter
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
action_permission_classes = {}
|
|
||||||
action_serializer_class = {
|
|
||||||
"list": ListChatroomSerializer,
|
|
||||||
"retrieve": RetrieveChatroomSerializer,
|
|
||||||
"create": CreateChatroomSerializer,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_serializer_class(self):
|
|
||||||
return self.action_serializer_class.get(self.action, ListChatroomSerializer)
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return ChatroomModel.objects.prefetch_related("members").only(
|
|
||||||
"id",
|
|
||||||
"type",
|
|
||||||
"auto_evaluation_id",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
|
||||||
results = list(queryset)
|
|
||||||
serializer = self.get_serializer(results, many=True)
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"count": len(results),
|
|
||||||
"next": None,
|
|
||||||
"previous": None,
|
|
||||||
"results": serializer.data,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
description="Xonaga yangi a'zo qo'shish",
|
|
||||||
request={"application/json": {"type": "object", "properties": {"user_id": {"type": "integer"}}}},
|
|
||||||
)
|
|
||||||
@action(detail=True, methods=["post"], url_path="add-member")
|
|
||||||
def add_member(self, request, pk=None):
|
|
||||||
room = self.get_object()
|
|
||||||
user_id = request.data.get("user_id")
|
|
||||||
if not user_id:
|
|
||||||
return Response({"detail": "user_id majburiy."}, status=400)
|
|
||||||
room.members.add(user_id)
|
|
||||||
return Response({"detail": "A'zo qo'shildi."})
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
description="Xonadan a'zoni chiqarish",
|
|
||||||
request={"application/json": {"type": "object", "properties": {"user_id": {"type": "integer"}}}},
|
|
||||||
)
|
|
||||||
@action(detail=True, methods=["post"], url_path="remove-member")
|
|
||||||
def remove_member(self, request, pk=None):
|
|
||||||
room = self.get_object()
|
|
||||||
user_id = request.data.get("user_id")
|
|
||||||
if not user_id:
|
|
||||||
return Response({"detail": "user_id majburiy."}, status=400)
|
|
||||||
room.members.remove(user_id)
|
|
||||||
return Response({"detail": "A'zo chiqarildi."})
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,157 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from unfold.admin import ModelAdmin
|
|
||||||
|
|
||||||
from core.apps.evaluation.choices.history import EvaluationEventType
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
class BaseHistoryAdmin(ModelAdmin):
|
|
||||||
"""
|
|
||||||
History yozuvlari o'zgartirib bo'lmaydi — faqat o'qiladi.
|
|
||||||
Signallar tomonidan avtomatik yoziladi.
|
|
||||||
"""
|
|
||||||
|
|
||||||
list_filter = (
|
|
||||||
"event_type",
|
|
||||||
"actor_role",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
search_fields = (
|
|
||||||
"actor_full_name",
|
|
||||||
"meta",
|
|
||||||
)
|
|
||||||
ordering = ("created_at",)
|
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def has_change_permission(self, request, obj=None):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def has_delete_permission(self, request, obj=None):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(AutoevaluationhistoryModel)
|
|
||||||
class AutoevaluationhistoryAdmin(BaseHistoryAdmin):
|
|
||||||
list_display = (
|
|
||||||
"id",
|
|
||||||
"auto_evaluation",
|
|
||||||
"event_type_colored",
|
|
||||||
"actor_full_name",
|
|
||||||
"actor_role",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
autocomplete_fields = ("auto_evaluation",)
|
|
||||||
readonly_fields = (
|
|
||||||
"auto_evaluation",
|
|
||||||
"event_type",
|
|
||||||
"actor_id",
|
|
||||||
"actor_full_name",
|
|
||||||
"actor_role",
|
|
||||||
"meta",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
fieldsets = (
|
|
||||||
(_("Baholash"), {
|
|
||||||
"fields": ("auto_evaluation",),
|
|
||||||
}),
|
|
||||||
(_("Hodisa"), {
|
|
||||||
"fields": (
|
|
||||||
"event_type",
|
|
||||||
"meta",
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
(_("Kim bajargan"), {
|
|
||||||
"fields": (
|
|
||||||
"actor_id",
|
|
||||||
"actor_full_name",
|
|
||||||
"actor_role",
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
(_("Tizim"), {
|
|
||||||
"classes": ("collapse",),
|
|
||||||
"fields": ("created_at",),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
@admin.display(description=_("Hodisa turi"))
|
|
||||||
def event_type_colored(self, obj):
|
|
||||||
colors = {
|
|
||||||
EvaluationEventType.ORDER_CREATED: "#16a34a",
|
|
||||||
EvaluationEventType.STATUS_CHANGED: "#2563eb",
|
|
||||||
EvaluationEventType.EVALUATOR_ASSIGNED: "#7c3aed",
|
|
||||||
EvaluationEventType.DOCUMENT_UPLOADED: "#d97706",
|
|
||||||
EvaluationEventType.PAYMENT_MADE: "#dc2626",
|
|
||||||
}
|
|
||||||
color = colors.get(obj.event_type, "#6b7280")
|
|
||||||
label = obj.get_event_type_display()
|
|
||||||
from django.utils.html import format_html
|
|
||||||
return format_html(
|
|
||||||
'<span style="color:{}; font-weight:600;">{}</span>',
|
|
||||||
color,
|
|
||||||
label,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(QuickevaluationhistoryModel)
|
|
||||||
class QuickevaluationhistoryAdmin(BaseHistoryAdmin):
|
|
||||||
list_display = (
|
|
||||||
"id",
|
|
||||||
"quick_evaluation",
|
|
||||||
"event_type_colored",
|
|
||||||
"actor_full_name",
|
|
||||||
"actor_role",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
autocomplete_fields = ("quick_evaluation",)
|
|
||||||
readonly_fields = (
|
|
||||||
"quick_evaluation",
|
|
||||||
"event_type",
|
|
||||||
"actor_id",
|
|
||||||
"actor_full_name",
|
|
||||||
"actor_role",
|
|
||||||
"meta",
|
|
||||||
"created_at",
|
|
||||||
)
|
|
||||||
fieldsets = (
|
|
||||||
(_("Tezkor baholash"), {
|
|
||||||
"fields": ("quick_evaluation",),
|
|
||||||
}),
|
|
||||||
(_("Hodisa"), {
|
|
||||||
"fields": (
|
|
||||||
"event_type",
|
|
||||||
"meta",
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
(_("Kim bajargan"), {
|
|
||||||
"fields": (
|
|
||||||
"actor_id",
|
|
||||||
"actor_full_name",
|
|
||||||
"actor_role",
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
(_("Tizim"), {
|
|
||||||
"classes": ("collapse",),
|
|
||||||
"fields": ("created_at",),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
@admin.display(description=_("Hodisa turi"))
|
|
||||||
def event_type_colored(self, obj):
|
|
||||||
colors = {
|
|
||||||
EvaluationEventType.ORDER_CREATED: "#16a34a",
|
|
||||||
EvaluationEventType.STATUS_CHANGED: "#2563eb",
|
|
||||||
EvaluationEventType.EVALUATOR_ASSIGNED: "#7c3aed",
|
|
||||||
EvaluationEventType.DOCUMENT_UPLOADED: "#d97706",
|
|
||||||
EvaluationEventType.PAYMENT_MADE: "#dc2626",
|
|
||||||
}
|
|
||||||
color = colors.get(obj.event_type, "#6b7280")
|
|
||||||
label = obj.get_event_type_display()
|
|
||||||
from django.utils.html import format_html
|
|
||||||
return format_html(
|
|
||||||
'<span style="color:{}; font-weight:600;">{}</span>',
|
|
||||||
color,
|
|
||||||
label,
|
|
||||||
)
|
|
||||||
@@ -24,7 +24,7 @@ class EvaluationrequestAdmin(ModelAdmin):
|
|||||||
"tex_passport",
|
"tex_passport",
|
||||||
"user__phone",
|
"user__phone",
|
||||||
)
|
)
|
||||||
readonly_fields = ("created_at", "updated_at")
|
readonly_fields = ("user", "created_at", "updated_at")
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
("Asosiy", {
|
("Asosiy", {
|
||||||
"fields": (
|
"fields": (
|
||||||
|
|||||||
@@ -4,6 +4,3 @@ from django.apps import AppConfig
|
|||||||
class ModuleConfig(AppConfig):
|
class ModuleConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "core.apps.evaluation"
|
name = "core.apps.evaluation"
|
||||||
|
|
||||||
def ready(self):
|
|
||||||
import core.apps.evaluation.signals # noqa
|
|
||||||
|
|||||||
@@ -21,6 +21,28 @@ class ObjectOwnerType(models.IntegerChoices):
|
|||||||
LEGAL = 2, _("Yuridik shaxs")
|
LEGAL = 2, _("Yuridik shaxs")
|
||||||
|
|
||||||
|
|
||||||
|
class PropertyRights(models.IntegerChoices):
|
||||||
|
PERMANENT_OWNERSHIP = 1, _("Doimiy egalik")
|
||||||
|
PERMANENT_USE = 2, _("Doimiy foydalanish")
|
||||||
|
TEMPORARY_USE = 3, _("Vaqtinchalik foydalanish")
|
||||||
|
TERM_LEASE = 4, _("Muddatli ijara")
|
||||||
|
LIFETIME_INHERITANCE = 5, _("Umrbod meros qilib olish")
|
||||||
|
|
||||||
|
|
||||||
|
class FormOwnership(models.IntegerChoices):
|
||||||
|
PRIVATE = 1, _("Xususiy")
|
||||||
|
STATE = 2, _("Davlat")
|
||||||
|
JSC = 3, _("AJ")
|
||||||
|
LLC = 4, _("MCHJ")
|
||||||
|
OTHER = 5, _("Boshqa")
|
||||||
|
|
||||||
|
|
||||||
|
class ValueDetermined(models.IntegerChoices):
|
||||||
|
MARKET_VALUE = 1, _("Bozor qiymati")
|
||||||
|
TAX_PURPOSE = 2, _("Soliq maqsadlari uchun")
|
||||||
|
LIQUIDATION_VALUE = 3, _("Tugatish qiymati")
|
||||||
|
UTILIZATION_VALUE = 4, _("Utilizatsiya qiymati")
|
||||||
|
|
||||||
|
|
||||||
class RateType(models.IntegerChoices):
|
class RateType(models.IntegerChoices):
|
||||||
CREDIT_COLLATERAL = 1, _("Kredit ta'minoti sifatida garovga qo'yish")
|
CREDIT_COLLATERAL = 1, _("Kredit ta'minoti sifatida garovga qo'yish")
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class EvaluationEventType(models.TextChoices):
|
|
||||||
ORDER_CREATED = "order_created", _("Buyurtma yaratildi")
|
|
||||||
STATUS_CHANGED = "status_changed", _("Status o'zgartirildi")
|
|
||||||
EVALUATOR_ASSIGNED = "evaluator_assigned", _("Baholovchi biriktirildi")
|
|
||||||
DOCUMENT_UPLOADED = "document_uploaded", _("Hujjat yuklandi")
|
|
||||||
PAYMENT_MADE = "payment_made", _("To'lov qilindi")
|
|
||||||
@@ -10,7 +10,3 @@ class ReferenceType(models.TextChoices):
|
|||||||
BODY_TYPE = "body_type", _("Body type")
|
BODY_TYPE = "body_type", _("Body type")
|
||||||
CAR_POSITION = "car_position", _("Car position")
|
CAR_POSITION = "car_position", _("Car position")
|
||||||
STATE_CAR = "state_car", _("Car state")
|
STATE_CAR = "state_car", _("Car state")
|
||||||
EVALUATION_PURPOSE = "evaluation_purpose", _("Evaluation purpose")
|
|
||||||
DETERMINED_VALUE = "determined_value", _("Determined value type")
|
|
||||||
PROPERTY_RIGHTS = "property_rights", _("Property rights")
|
|
||||||
OWNERSHIP_FORM = "ownership_form", _("Ownership form")
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
from django_filters import rest_framework as filters
|
|
||||||
|
|
||||||
from core.apps.evaluation.choices.history import EvaluationEventType
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
class AutoevaluationhistoryFilter(filters.FilterSet):
|
|
||||||
auto_evaluation = filters.NumberFilter(
|
|
||||||
field_name="auto_evaluation", lookup_expr="exact"
|
|
||||||
)
|
|
||||||
event_type = filters.ChoiceFilter(
|
|
||||||
field_name="event_type",
|
|
||||||
choices=EvaluationEventType.choices,
|
|
||||||
)
|
|
||||||
created_from = filters.DateTimeFilter(
|
|
||||||
field_name="created_at", lookup_expr="gte"
|
|
||||||
)
|
|
||||||
created_to = filters.DateTimeFilter(
|
|
||||||
field_name="created_at", lookup_expr="lte"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = AutoevaluationhistoryModel
|
|
||||||
fields = [
|
|
||||||
"auto_evaluation",
|
|
||||||
"event_type",
|
|
||||||
"created_from",
|
|
||||||
"created_to",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class QuickevaluationhistoryFilter(filters.FilterSet):
|
|
||||||
quick_evaluation = filters.NumberFilter(
|
|
||||||
field_name="quick_evaluation", lookup_expr="exact"
|
|
||||||
)
|
|
||||||
event_type = filters.ChoiceFilter(
|
|
||||||
field_name="event_type",
|
|
||||||
choices=EvaluationEventType.choices,
|
|
||||||
)
|
|
||||||
created_from = filters.DateTimeFilter(
|
|
||||||
field_name="created_at", lookup_expr="gte"
|
|
||||||
)
|
|
||||||
created_to = filters.DateTimeFilter(
|
|
||||||
field_name="created_at", lookup_expr="lte"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = QuickevaluationhistoryModel
|
|
||||||
fields = [
|
|
||||||
"quick_evaluation",
|
|
||||||
"event_type",
|
|
||||||
"created_from",
|
|
||||||
"created_to",
|
|
||||||
]
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
from django import forms
|
|
||||||
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
class AutoevaluationhistoryForm(forms.ModelForm):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = AutoevaluationhistoryModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class QuickevaluationhistoryForm(forms.ModelForm):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = QuickevaluationhistoryModel
|
|
||||||
fields = "__all__"
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-03-17 13:34
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0018_evaluationrequestmodel'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='location_name',
|
|
||||||
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='location name'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='chassi',
|
|
||||||
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='chassi'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-03-17 14:22
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0019_evaluationrequestmodel_location_name_and_more'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='referenceitemmodel',
|
|
||||||
name='type',
|
|
||||||
field=models.CharField(choices=[('brand', 'Brand'), ('marka', 'Marka'), ('color', 'Color'), ('fuel_type', 'Fuel type'), ('body_type', 'Body type'), ('car_position', 'Car position'), ('state_car', 'Car state'), ('evaluation_purpose', 'Evaluation purpose')], max_length=50, verbose_name='type'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-03-17 15:14
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0020_alter_referenceitemmodel_type'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='referenceitemmodel',
|
|
||||||
name='type',
|
|
||||||
field=models.CharField(choices=[('brand', 'Brand'), ('marka', 'Marka'), ('color', 'Color'), ('fuel_type', 'Fuel type'), ('body_type', 'Body type'), ('car_position', 'Car position'), ('state_car', 'Car state'), ('evaluation_purpose', 'Evaluation purpose'), ('determined_value', 'Determined value type')], max_length=50, verbose_name='type'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-03-18 08:20
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0021_alter_referenceitemmodel_type'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='referenceitemmodel',
|
|
||||||
name='type',
|
|
||||||
field=models.CharField(choices=[('brand', 'Brand'), ('marka', 'Marka'), ('color', 'Color'), ('fuel_type', 'Fuel type'), ('body_type', 'Body type'), ('car_position', 'Car position'), ('state_car', 'Car state'), ('evaluation_purpose', 'Evaluation purpose'), ('determined_value', 'Determined value type'), ('property_rights', 'Property rights'), ('ownership_form', 'Ownership form')], max_length=50, verbose_name='type'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-04-02 10:03
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0022_alter_referenceitemmodel_type'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='AutoevaluationhistoryModel',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('event_type', models.CharField(choices=[('order_created', 'Buyurtma yaratildi'), ('status_changed', "Status o'zgartirildi"), ('evaluator_assigned', 'Baholovchi biriktirildi'), ('document_uploaded', 'Hujjat yuklandi'), ('payment_made', "To'lov qilindi")], max_length=50, verbose_name='event type')),
|
|
||||||
('actor_id', models.BigIntegerField(blank=True, null=True, verbose_name='actor id')),
|
|
||||||
('actor_full_name', models.CharField(default='Tizim', max_length=255, verbose_name='actor full name')),
|
|
||||||
('actor_role', models.CharField(default='system', max_length=50, verbose_name='actor role')),
|
|
||||||
('meta', models.JSONField(blank=True, default=dict, verbose_name='meta')),
|
|
||||||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
|
|
||||||
('auto_evaluation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='history', to='evaluation.autoevaluationmodel', verbose_name='auto evaluation')),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'Auto Evaluation History',
|
|
||||||
'verbose_name_plural': 'Auto Evaluation Histories',
|
|
||||||
'db_table': 'AutoEvaluationHistory',
|
|
||||||
'ordering': ['created_at'],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='QuickevaluationhistoryModel',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('event_type', models.CharField(choices=[('order_created', 'Buyurtma yaratildi'), ('status_changed', "Status o'zgartirildi"), ('evaluator_assigned', 'Baholovchi biriktirildi'), ('document_uploaded', 'Hujjat yuklandi'), ('payment_made', "To'lov qilindi")], max_length=50, verbose_name='event type')),
|
|
||||||
('actor_id', models.BigIntegerField(blank=True, null=True, verbose_name='actor id')),
|
|
||||||
('actor_full_name', models.CharField(default='Tizim', max_length=255, verbose_name='actor full name')),
|
|
||||||
('actor_role', models.CharField(default='system', max_length=50, verbose_name='actor role')),
|
|
||||||
('meta', models.JSONField(blank=True, default=dict, verbose_name='meta')),
|
|
||||||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
|
|
||||||
('quick_evaluation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='history', to='evaluation.quickevaluationmodel', verbose_name='quick evaluation')),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'Quick Evaluation History',
|
|
||||||
'verbose_name_plural': 'Quick Evaluation Histories',
|
|
||||||
'db_table': 'QuickEvaluationHistory',
|
|
||||||
'ordering': ['created_at'],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-04-02 11:08
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0023_autoevaluationhistorymodel_and_more'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name='autoevaluationhistorymodel',
|
|
||||||
index=models.Index(fields=['auto_evaluation_id', 'created_at'], name='auto_hist_eval_date_idx'),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name='autoevaluationhistorymodel',
|
|
||||||
index=models.Index(fields=['event_type'], name='auto_hist_event_type_idx'),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name='quickevaluationhistorymodel',
|
|
||||||
index=models.Index(fields=['quick_evaluation_id', 'created_at'], name='quick_hist_eval_date_idx'),
|
|
||||||
),
|
|
||||||
migrations.AddIndex(
|
|
||||||
model_name='quickevaluationhistorymodel',
|
|
||||||
index=models.Index(fields=['event_type'], name='quick_hist_event_type_idx'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-04-02 12:34
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0024_add_history_indexes'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='form_ownership',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_form_ownership_requests', to='evaluation.referenceitemmodel', verbose_name='form ownership'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='property_rights',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_property_rights_requests', to='evaluation.referenceitemmodel', verbose_name='property rights'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='rate_goal',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_rate_goal_requests', to='evaluation.referenceitemmodel', verbose_name='rate goal'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='evaluationrequestmodel',
|
|
||||||
name='value_determined',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_value_determined_requests', to='evaluation.referenceitemmodel', verbose_name='value determined'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# Generated by Django 5.2.7 on 2026-04-02 13:24
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('evaluation', '0025_alter_evaluationrequestmodel_form_ownership_and_more'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
# Mavjud integer qiymatlar ReferenceItem'da yo'q — FK qo'yishdan oldin NULL qilamiz
|
|
||||||
migrations.RunSQL(
|
|
||||||
sql="""
|
|
||||||
UPDATE "AutoEvaluation"
|
|
||||||
SET form_ownership = NULL,
|
|
||||||
property_rights = NULL,
|
|
||||||
rate_type = NULL,
|
|
||||||
value_determined = NULL;
|
|
||||||
""",
|
|
||||||
reverse_sql=migrations.RunSQL.noop,
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='autoevaluationmodel',
|
|
||||||
name='form_ownership',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_auto_form_ownership', to='evaluation.referenceitemmodel', verbose_name='form of ownership'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='autoevaluationmodel',
|
|
||||||
name='property_rights',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_auto_property_rights', to='evaluation.referenceitemmodel', verbose_name='property rights'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='autoevaluationmodel',
|
|
||||||
name='rate_type',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_auto_rate_type', to='evaluation.referenceitemmodel', verbose_name='rate type'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='autoevaluationmodel',
|
|
||||||
name='value_determined',
|
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='evaluation_auto_value_determined', to='evaluation.referenceitemmodel', verbose_name='value determined'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ from core.apps.evaluation.choices.auto import (
|
|||||||
AutoCarWheel,
|
AutoCarWheel,
|
||||||
AutoEvaluationStatus,
|
AutoEvaluationStatus,
|
||||||
AutoObjectType,
|
AutoObjectType,
|
||||||
# FormOwnership,
|
FormOwnership,
|
||||||
LocationConvenience,
|
LocationConvenience,
|
||||||
LocationHighways,
|
LocationHighways,
|
||||||
ObjectOwnerType,
|
ObjectOwnerType,
|
||||||
# PropertyRights,
|
PropertyRights,
|
||||||
# RateType,
|
RateType,
|
||||||
# ValueDetermined,
|
ValueDetermined,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .valuation import ValuationModel
|
from .valuation import ValuationModel
|
||||||
@@ -123,38 +123,29 @@ class AutoEvaluationModel(AbstractBaseModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
|
property_rights = models.IntegerField(
|
||||||
property_rights = models.ForeignKey(
|
|
||||||
'evaluation.ReferenceitemModel',
|
|
||||||
verbose_name=_("property rights"),
|
verbose_name=_("property rights"),
|
||||||
|
choices=PropertyRights.choices,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='evaluation_auto_property_rights'
|
|
||||||
)
|
)
|
||||||
form_ownership = models.ForeignKey(
|
form_ownership = models.IntegerField(
|
||||||
'evaluation.ReferenceitemModel',
|
|
||||||
verbose_name=_("form of ownership"),
|
verbose_name=_("form of ownership"),
|
||||||
|
choices=FormOwnership.choices,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='evaluation_auto_form_ownership'
|
|
||||||
)
|
)
|
||||||
value_determined = models.ForeignKey(
|
value_determined = models.IntegerField(
|
||||||
'evaluation.ReferenceitemModel',
|
|
||||||
verbose_name=_("value determined"),
|
verbose_name=_("value determined"),
|
||||||
|
choices=ValueDetermined.choices,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='evaluation_auto_value_determined'
|
|
||||||
)
|
)
|
||||||
rate_type = models.ForeignKey(
|
rate_type = models.IntegerField(
|
||||||
'evaluation.ReferenceitemModel',
|
|
||||||
verbose_name=_("rate type"),
|
verbose_name=_("rate type"),
|
||||||
|
choices=RateType.choices,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
related_name='evaluation_auto_rate_type'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── Step 3 — Manzil ma'lumotlari ────────────────────────────────
|
# ── Step 3 — Manzil ma'lumotlari ────────────────────────────────
|
||||||
@@ -299,3 +290,4 @@ class AutoEvaluationModel(AbstractBaseModel):
|
|||||||
db_table = "AutoEvaluation"
|
db_table = "AutoEvaluation"
|
||||||
verbose_name = _("Auto Evaluation")
|
verbose_name = _("Auto Evaluation")
|
||||||
verbose_name_plural = _("Auto Evaluations")
|
verbose_name_plural = _("Auto Evaluations")
|
||||||
|
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from model_bakery import baker
|
|
||||||
|
|
||||||
from core.apps.evaluation.choices.history import EvaluationEventType
|
|
||||||
|
|
||||||
|
|
||||||
class AutoevaluationhistoryModel(models.Model):
|
|
||||||
"""AutoEvaluation bo'yicha barcha harakatlar logi — faqat o'qiladi, signallar tomonidan yoziladi."""
|
|
||||||
|
|
||||||
auto_evaluation = models.ForeignKey(
|
|
||||||
"evaluation.AutoEvaluationModel",
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name="history",
|
|
||||||
verbose_name=_("auto evaluation"),
|
|
||||||
)
|
|
||||||
event_type = models.CharField(
|
|
||||||
verbose_name=_("event type"),
|
|
||||||
max_length=50,
|
|
||||||
choices=EvaluationEventType.choices,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Actor — kim bajargan (system bo'lsa actor_id=None)
|
|
||||||
actor_id = models.BigIntegerField(
|
|
||||||
verbose_name=_("actor id"),
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
)
|
|
||||||
actor_full_name = models.CharField(
|
|
||||||
verbose_name=_("actor full name"),
|
|
||||||
max_length=255,
|
|
||||||
default="Tizim",
|
|
||||||
)
|
|
||||||
actor_role = models.CharField(
|
|
||||||
verbose_name=_("actor role"),
|
|
||||||
max_length=50,
|
|
||||||
default="system",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Har bir event_type uchun turli struktura
|
|
||||||
meta = models.JSONField(
|
|
||||||
verbose_name=_("meta"),
|
|
||||||
default=dict,
|
|
||||||
blank=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
created_at = models.DateTimeField(
|
|
||||||
verbose_name=_("created at"),
|
|
||||||
auto_now_add=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.get_event_type_display()} — AutoEval #{self.auto_evaluation_id}"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _baker(cls):
|
|
||||||
return baker.make(cls)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = "AutoEvaluationHistory"
|
|
||||||
verbose_name = _("Auto Evaluation History")
|
|
||||||
verbose_name_plural = _("Auto Evaluation Histories")
|
|
||||||
ordering = ["created_at"]
|
|
||||||
indexes = [
|
|
||||||
# Asosiy query: bir baholash tarixi + sana bo'yicha tartib
|
|
||||||
models.Index(fields=["auto_evaluation_id", "created_at"], name="auto_hist_eval_date_idx"),
|
|
||||||
# event_type bo'yicha filter
|
|
||||||
models.Index(fields=["event_type"], name="auto_hist_event_type_idx"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class QuickevaluationhistoryModel(models.Model):
|
|
||||||
"""QuickEvaluation bo'yicha barcha harakatlar logi — faqat o'qiladi, signallar tomonidan yoziladi."""
|
|
||||||
|
|
||||||
quick_evaluation = models.ForeignKey(
|
|
||||||
"evaluation.QuickEvaluationModel",
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
related_name="history",
|
|
||||||
verbose_name=_("quick evaluation"),
|
|
||||||
)
|
|
||||||
event_type = models.CharField(
|
|
||||||
verbose_name=_("event type"),
|
|
||||||
max_length=50,
|
|
||||||
choices=EvaluationEventType.choices,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Actor — kim bajargan (system bo'lsa actor_id=None)
|
|
||||||
actor_id = models.BigIntegerField(
|
|
||||||
verbose_name=_("actor id"),
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
)
|
|
||||||
actor_full_name = models.CharField(
|
|
||||||
verbose_name=_("actor full name"),
|
|
||||||
max_length=255,
|
|
||||||
default="Tizim",
|
|
||||||
)
|
|
||||||
actor_role = models.CharField(
|
|
||||||
verbose_name=_("actor role"),
|
|
||||||
max_length=50,
|
|
||||||
default="system",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Har bir event_type uchun turli struktura
|
|
||||||
meta = models.JSONField(
|
|
||||||
verbose_name=_("meta"),
|
|
||||||
default=dict,
|
|
||||||
blank=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
created_at = models.DateTimeField(
|
|
||||||
verbose_name=_("created at"),
|
|
||||||
auto_now_add=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.get_event_type_display()} — QuickEval #{self.quick_evaluation_id}"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _baker(cls):
|
|
||||||
return baker.make(cls)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = "QuickEvaluationHistory"
|
|
||||||
verbose_name = _("Quick Evaluation History")
|
|
||||||
verbose_name_plural = _("Quick Evaluation Histories")
|
|
||||||
ordering = ["created_at"]
|
|
||||||
indexes = [
|
|
||||||
# Asosiy query: bir baholash tarixi + sana bo'yicha tartib
|
|
||||||
models.Index(fields=["quick_evaluation_id", "created_at"], name="quick_hist_eval_date_idx"),
|
|
||||||
# event_type bo'yicha filter
|
|
||||||
models.Index(fields=["event_type"], name="quick_hist_event_type_idx"),
|
|
||||||
]
|
|
||||||
@@ -9,7 +9,6 @@ from core.apps.evaluation.choices.request import (
|
|||||||
RequestObjectType,
|
RequestObjectType,
|
||||||
RequestStatus,
|
RequestStatus,
|
||||||
)
|
)
|
||||||
from core.apps.evaluation.models import ReferenceitemModel
|
|
||||||
|
|
||||||
|
|
||||||
class EvaluationrequestModel(AbstractBaseModel):
|
class EvaluationrequestModel(AbstractBaseModel):
|
||||||
@@ -45,46 +44,29 @@ class EvaluationrequestModel(AbstractBaseModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
value_determined = models.ForeignKey(
|
value_determined = models.CharField(
|
||||||
"evaluation.ReferenceitemModel",
|
|
||||||
verbose_name=_("value determined"),
|
verbose_name=_("value determined"),
|
||||||
related_name="evaluation_value_determined_requests",
|
max_length=100,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
)
|
)
|
||||||
rate_goal = models.ForeignKey(
|
rate_goal = models.CharField(
|
||||||
"evaluation.ReferenceitemModel",
|
|
||||||
verbose_name=_("rate goal"),
|
verbose_name=_("rate goal"),
|
||||||
related_name="evaluation_rate_goal_requests",
|
max_length=100,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
)
|
)
|
||||||
property_rights = models.ForeignKey(
|
property_rights = models.CharField(
|
||||||
"evaluation.ReferenceitemModel",
|
|
||||||
verbose_name=_("property rights"),
|
verbose_name=_("property rights"),
|
||||||
related_name="evaluation_property_rights_requests",
|
max_length=100,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
)
|
)
|
||||||
form_ownership = models.ForeignKey(
|
form_ownership = models.CharField(
|
||||||
"evaluation.ReferenceitemModel",
|
|
||||||
verbose_name=_("form ownership"),
|
verbose_name=_("form ownership"),
|
||||||
related_name="evaluation_form_ownership_requests",
|
max_length=100,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
)
|
)
|
||||||
worked_hours = models.IntegerField(
|
worked_hours = models.IntegerField(
|
||||||
verbose_name=_("worked hours"),
|
verbose_name=_("worked hours"),
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
chassi = models.CharField(
|
chassi = models.IntegerField(
|
||||||
verbose_name=_("chassi"),
|
verbose_name=_("chassi"),
|
||||||
max_length=100,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
@@ -92,12 +74,6 @@ class EvaluationrequestModel(AbstractBaseModel):
|
|||||||
verbose_name=_("need delivering"),
|
verbose_name=_("need delivering"),
|
||||||
default=True,
|
default=True,
|
||||||
)
|
)
|
||||||
location_name = models.CharField(
|
|
||||||
verbose_name=_("location name"),
|
|
||||||
max_length=255,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
)
|
|
||||||
location_lat = models.DecimalField(
|
location_lat = models.DecimalField(
|
||||||
verbose_name=_("location latitude"),
|
verbose_name=_("location latitude"),
|
||||||
max_digits=9,
|
max_digits=9,
|
||||||
@@ -118,26 +94,22 @@ class EvaluationrequestModel(AbstractBaseModel):
|
|||||||
choices=RequestStatus.choices,
|
choices=RequestStatus.choices,
|
||||||
default=RequestStatus.PENDING,
|
default=RequestStatus.PENDING,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Request #{self.pk} — {self.get_rate_type_display()}"
|
return f"Requests #{self.pk} — {self.get_rate_type_display()}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _baker(cls):
|
def _baker(cls):
|
||||||
user = baker.make(settings.AUTH_USER_MODEL)
|
user = baker.make(settings.AUTH_USER_MODEL)
|
||||||
reference = ReferenceitemModel.objects.create(
|
|
||||||
name="test"
|
|
||||||
)
|
|
||||||
return baker.make(
|
return baker.make(
|
||||||
cls,
|
cls,
|
||||||
user=user,
|
user=user,
|
||||||
rate_type=EvaluationRateType.AUTO,
|
rate_type=EvaluationRateType.AUTO,
|
||||||
customer_inn_number="123456789",
|
customer_inn_number="123456789",
|
||||||
owner_inn_number="987654321",
|
owner_inn_number="987654321",
|
||||||
value_determined=reference,
|
value_determined="Bozor qiymati",
|
||||||
rate_goal=reference,
|
rate_goal="Kredit uchun",
|
||||||
property_rights=reference,
|
property_rights="Xususiy",
|
||||||
form_ownership=reference,
|
form_ownership="Xususiy",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
from rest_framework import permissions
|
|
||||||
|
|
||||||
|
|
||||||
class AutoevaluationhistoryPermission(permissions.BasePermission):
|
|
||||||
|
|
||||||
def __init__(self) -> None: ...
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class QuickevaluationhistoryPermission(permissions.BasePermission):
|
|
||||||
|
|
||||||
def __init__(self) -> None: ...
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
|
||||||
return True
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ import re
|
|||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from core.apps.evaluation.models import AutoEvaluationModel,ReferenceitemModel
|
from core.apps.evaluation.models import AutoEvaluationModel
|
||||||
from core.apps.evaluation.serializers.reference import ListReferenceitemSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAutoevaluationSerializer(serializers.ModelSerializer):
|
class BaseAutoevaluationSerializer(serializers.ModelSerializer):
|
||||||
status_display = serializers.CharField(source="get_status_display", read_only=True)
|
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_type_display = serializers.CharField(source="get_object_type_display", read_only=True, default=None)
|
||||||
|
rate_type_display = serializers.CharField(source="get_rate_type_display", read_only=True, default=None)
|
||||||
|
value_determined_display = serializers.CharField(source="get_value_determined_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)
|
property_rights_display = serializers.CharField(source="get_property_rights_display", read_only=True, default=None)
|
||||||
value_determined = ListReferenceitemSerializer(read_only=True)
|
form_ownership_display = serializers.CharField(source="get_form_ownership_display", read_only=True, default=None)
|
||||||
property_rights = ListReferenceitemSerializer(read_only=True)
|
|
||||||
form_ownership = ListReferenceitemSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AutoEvaluationModel
|
model = AutoEvaluationModel
|
||||||
@@ -27,13 +26,13 @@ class BaseAutoevaluationSerializer(serializers.ModelSerializer):
|
|||||||
"car_number",
|
"car_number",
|
||||||
"manufacture_year",
|
"manufacture_year",
|
||||||
"car_color",
|
"car_color",
|
||||||
|
"rate_type",
|
||||||
|
"rate_type_display",
|
||||||
|
"value_determined",
|
||||||
|
"value_determined_display",
|
||||||
"status",
|
"status",
|
||||||
"status_display",
|
"status_display",
|
||||||
"created_at",
|
"created_at",
|
||||||
"value_determined",
|
|
||||||
"rate_type",
|
|
||||||
"property_rights",
|
|
||||||
"form_ownership",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +68,10 @@ class RetrieveAutoevaluationSerializer(BaseAutoevaluationSerializer):
|
|||||||
"object_owner_individual_person_passport_num",
|
"object_owner_individual_person_passport_num",
|
||||||
"object_owner_legal_entity",
|
"object_owner_legal_entity",
|
||||||
"object_owner_legal_inn",
|
"object_owner_legal_inn",
|
||||||
|
"property_rights",
|
||||||
|
"property_rights_display",
|
||||||
|
"form_ownership",
|
||||||
|
"form_ownership_display",
|
||||||
# Step 3
|
# Step 3
|
||||||
"object_location_province",
|
"object_location_province",
|
||||||
"object_location_district",
|
"object_location_district",
|
||||||
@@ -98,33 +101,6 @@ class RetrieveAutoevaluationSerializer(BaseAutoevaluationSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CreateAutoevaluationSerializer(serializers.ModelSerializer):
|
class CreateAutoevaluationSerializer(serializers.ModelSerializer):
|
||||||
property_rights = serializers.PrimaryKeyRelatedField(
|
|
||||||
queryset=ReferenceitemModel.objects.all(),
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
)
|
|
||||||
value_determined = serializers.PrimaryKeyRelatedField(
|
|
||||||
queryset=ReferenceitemModel.objects.all(),
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
)
|
|
||||||
form_ownership = serializers.PrimaryKeyRelatedField(
|
|
||||||
queryset=ReferenceitemModel.objects.all(),
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
)
|
|
||||||
value_determined = serializers.PrimaryKeyRelatedField(
|
|
||||||
queryset=ReferenceitemModel.objects.all(),
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
)
|
|
||||||
rate_type = serializers.PrimaryKeyRelatedField(
|
|
||||||
queryset=ReferenceitemModel.objects.all(),
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AutoEvaluationModel
|
model = AutoEvaluationModel
|
||||||
fields = [
|
fields = [
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAutoevaluationhistorySerializer(serializers.ModelSerializer):
|
|
||||||
event_type_display = serializers.CharField(source="get_event_type_display", read_only=True)
|
|
||||||
actor = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_actor(self, obj):
|
|
||||||
return {
|
|
||||||
"id": obj.actor_id,
|
|
||||||
"full_name": obj.actor_full_name,
|
|
||||||
"role": obj.actor_role,
|
|
||||||
}
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = AutoevaluationhistoryModel
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"event_type",
|
|
||||||
"event_type_display",
|
|
||||||
"actor",
|
|
||||||
"meta",
|
|
||||||
"created_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ListAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
|
||||||
class Meta(BaseAutoevaluationhistorySerializer.Meta): ...
|
|
||||||
|
|
||||||
|
|
||||||
class RetrieveAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
|
||||||
class Meta(BaseAutoevaluationhistorySerializer.Meta):
|
|
||||||
fields = BaseAutoevaluationhistorySerializer.Meta.fields + ["auto_evaluation"]
|
|
||||||
|
|
||||||
|
|
||||||
class CreateAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
|
||||||
class Meta(BaseAutoevaluationhistorySerializer.Meta): ...
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from core.apps.evaluation.models import QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
class BaseQuickevaluationhistorySerializer(serializers.ModelSerializer):
|
|
||||||
event_type_display = serializers.CharField(source="get_event_type_display", read_only=True)
|
|
||||||
actor = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
def get_actor(self, obj):
|
|
||||||
return {
|
|
||||||
"id": obj.actor_id,
|
|
||||||
"full_name": obj.actor_full_name,
|
|
||||||
"role": obj.actor_role,
|
|
||||||
}
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = QuickevaluationhistoryModel
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"event_type",
|
|
||||||
"event_type_display",
|
|
||||||
"actor",
|
|
||||||
"meta",
|
|
||||||
"created_at",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ListQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
|
||||||
class Meta(BaseQuickevaluationhistorySerializer.Meta): ...
|
|
||||||
|
|
||||||
|
|
||||||
class RetrieveQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
|
||||||
class Meta(BaseQuickevaluationhistorySerializer.Meta):
|
|
||||||
fields = BaseQuickevaluationhistorySerializer.Meta.fields + ["quick_evaluation"]
|
|
||||||
|
|
||||||
|
|
||||||
class CreateQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
|
||||||
class Meta(BaseQuickevaluationhistorySerializer.Meta): ...
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from .AutoEvaluationHistory import * # noqa
|
|
||||||
from .QuickEvaluationHistory import * # noqa
|
|
||||||
@@ -46,30 +46,3 @@ class CreateReferenceitemSerializer(BaseReferenceitemSerializer):
|
|||||||
"order",
|
"order",
|
||||||
"is_active",
|
"is_active",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EvaluationPurposeSerializer(serializers.ModelSerializer):
|
|
||||||
label = serializers.CharField(source="name")
|
|
||||||
value = serializers.IntegerField(source="id")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ReferenceitemModel
|
|
||||||
fields = ["label", "value"]
|
|
||||||
|
|
||||||
|
|
||||||
class DeterminedValueSerializer(serializers.ModelSerializer):
|
|
||||||
label = serializers.CharField(source="name")
|
|
||||||
value = serializers.IntegerField(source="id")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ReferenceitemModel
|
|
||||||
fields = ["label", "value"]
|
|
||||||
|
|
||||||
|
|
||||||
class LabelValueSerializer(serializers.ModelSerializer):
|
|
||||||
label = serializers.CharField(source="name")
|
|
||||||
value = serializers.IntegerField(source="id")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ReferenceitemModel
|
|
||||||
fields = ["label", "value"]
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import re
|
|||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from core.apps.evaluation.models import EvaluationrequestModel, ReferenceitemModel
|
from core.apps.evaluation.models import EvaluationrequestModel
|
||||||
from core.apps.evaluation.serializers.reference import ListReferenceitemSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||||
@@ -18,12 +17,6 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
)
|
)
|
||||||
location = serializers.SerializerMethodField()
|
location = serializers.SerializerMethodField()
|
||||||
|
|
||||||
location_name = serializers.CharField(required=False)
|
|
||||||
value_determined = ListReferenceitemSerializer(read_only=True)
|
|
||||||
rate_goal = ListReferenceitemSerializer(read_only=True)
|
|
||||||
property_rights = ListReferenceitemSerializer(read_only=True)
|
|
||||||
form_ownership = ListReferenceitemSerializer(read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = EvaluationrequestModel
|
model = EvaluationrequestModel
|
||||||
fields = [
|
fields = [
|
||||||
@@ -43,7 +36,6 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
"chassi",
|
"chassi",
|
||||||
"need_delivering",
|
"need_delivering",
|
||||||
"location",
|
"location",
|
||||||
"location_name",
|
|
||||||
"status",
|
"status",
|
||||||
"status_display",
|
"status_display",
|
||||||
"created_at",
|
"created_at",
|
||||||
@@ -52,11 +44,7 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_location(self, obj):
|
def get_location(self, obj):
|
||||||
if obj.location_lat is not None and obj.location_lng is not None:
|
if obj.location_lat is not None and obj.location_lng is not None:
|
||||||
return {
|
return {"lat": float(obj.location_lat), "lng": float(obj.location_lng)}
|
||||||
"lat": float(obj.location_lat),
|
|
||||||
"lng": float(obj.location_lng),
|
|
||||||
"name": obj.location_name
|
|
||||||
}
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -71,50 +59,26 @@ class RetrieveEvaluationrequestSerializer(BaseEvaluationrequestSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||||
location = serializers.DictField(required=False, allow_empty=True)
|
location = serializers.DictField(
|
||||||
|
child=serializers.FloatField(), required=False
|
||||||
# locationName — string qabul qiladi, location ichida yoki tashqarida yuborsa bo'ladi
|
|
||||||
locationName = serializers.CharField(
|
|
||||||
write_only=True,
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
allow_blank=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Faqat truck_car uchun majburiy — field darajasida optional qilib belgilaymiz,
|
|
||||||
# validate() da object_type ga qarab tekshiramiz
|
|
||||||
worked_hours = serializers.IntegerField(
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
)
|
|
||||||
chassi = serializers.CharField(
|
|
||||||
required=False,
|
|
||||||
allow_null=True,
|
|
||||||
allow_blank=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
value_determined = serializers.IntegerField(required=False, allow_null=True)
|
|
||||||
rate_goal = serializers.IntegerField(required=False, allow_null=True)
|
|
||||||
property_rights = serializers.IntegerField(required=False, allow_null=True)
|
|
||||||
form_ownership = serializers.IntegerField(required=False, allow_null=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = EvaluationrequestModel
|
model = EvaluationrequestModel
|
||||||
fields = [
|
fields = [
|
||||||
"value_determined",
|
|
||||||
"rate_goal",
|
|
||||||
"property_rights",
|
|
||||||
"form_ownership",
|
|
||||||
"rate_type",
|
"rate_type",
|
||||||
"object_type",
|
"object_type",
|
||||||
"customer_inn_number",
|
"customer_inn_number",
|
||||||
"owner_inn_number",
|
"owner_inn_number",
|
||||||
"tex_passport",
|
"tex_passport",
|
||||||
|
"value_determined",
|
||||||
|
"rate_goal",
|
||||||
|
"property_rights",
|
||||||
|
"form_ownership",
|
||||||
"worked_hours",
|
"worked_hours",
|
||||||
"chassi",
|
"chassi",
|
||||||
"need_delivering",
|
"need_delivering",
|
||||||
"location",
|
"location",
|
||||||
"locationName",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def validate_tex_passport(self, value):
|
def validate_tex_passport(self, value):
|
||||||
@@ -128,65 +92,41 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
rate_type = attrs.get("rate_type")
|
rate_type = attrs.get("rate_type")
|
||||||
object_type = attrs.get("object_type")
|
object_type = attrs.get("object_type")
|
||||||
|
|
||||||
|
# object_type majburiy agar rate_type=auto
|
||||||
if rate_type == "auto" and not object_type:
|
if rate_type == "auto" and not object_type:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"object_type": "rate_type 'auto' bo'lganda object_type majburiy."}
|
{"object_type": "rate_type 'auto' bo'lganda object_type majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# tex_passport majburiy agar rate_type=auto
|
||||||
if rate_type == "auto" and not attrs.get("tex_passport"):
|
if rate_type == "auto" and not attrs.get("tex_passport"):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"tex_passport": "rate_type 'auto' bo'lganda tex_passport majburiy."}
|
{"tex_passport": "rate_type 'auto' bo'lganda tex_passport majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
# worked_hours va chassi FAQAT yuk avtomobil (truck_car) uchun majburiy
|
# worked_hours va chassi majburiy agar object_type=truck_car
|
||||||
if object_type == "truck_car":
|
if object_type == "truck_car":
|
||||||
if attrs.get("worked_hours") is None:
|
if attrs.get("worked_hours") is None:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"worked_hours": "Yuk avtomobil uchun ishlagan soati majburiy."}
|
{"worked_hours": "Yuk automobil uchun ishlagan soati majburiy."}
|
||||||
)
|
)
|
||||||
if not attrs.get("chassi"):
|
if attrs.get("chassi") is None:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"chassi": "Yuk avtomobil uchun shassi raqami majburiy."}
|
{"chassi": "Yuk automobil uchun shassi majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
if attrs.get("value_determined"):
|
# location majburiy agar need_delivering=true
|
||||||
if attrs.get("value_determined") not in ReferenceitemModel.objects.values_list("id", flat=True):
|
if attrs.get("need_delivering", True) and not attrs.get("location"):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"value_determined": "Noto'g'ri qiymat aniqlandi."}
|
{"location": "Yetkazish kerak bo'lganda manzil majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
if attrs.get("rate_goal"):
|
|
||||||
if attrs.get("rate_goal") not in ReferenceitemModel.objects.values_list("id", flat=True):
|
|
||||||
raise serializers.ValidationError(
|
|
||||||
{"rate_goal": "Noto'g'ri qiymat aniqlandi."}
|
|
||||||
)
|
|
||||||
|
|
||||||
if attrs.get("property_rights"):
|
|
||||||
if attrs.get("property_rights") not in ReferenceitemModel.objects.values_list("id", flat=True):
|
|
||||||
raise serializers.ValidationError(
|
|
||||||
{"property_rights": "Noto'g'ri qiymat aniqlandi."}
|
|
||||||
)
|
|
||||||
|
|
||||||
if attrs.get("form_ownership"):
|
|
||||||
if attrs.get("form_ownership") not in ReferenceitemModel.objects.values_list("id", flat=True):
|
|
||||||
raise serializers.ValidationError(
|
|
||||||
{"form_ownership": "Noto'g'ri qiymat aniqlandi."}
|
|
||||||
)
|
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
location = validated_data.pop("location", None)
|
location = validated_data.pop("location", None)
|
||||||
location_name = validated_data.pop("locationName", None)
|
|
||||||
|
|
||||||
if location:
|
if location:
|
||||||
validated_data["location_lat"] = location.get("lat")
|
validated_data["location_lat"] = location.get("lat")
|
||||||
validated_data["location_lng"] = location.get("lng")
|
validated_data["location_lng"] = location.get("lng")
|
||||||
if not location_name:
|
|
||||||
location_name = location.get("name") or location.get("locationName")
|
|
||||||
|
|
||||||
if 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)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
from .history import EvaluationHistoryService # noqa
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
from core.apps.evaluation.choices.history import EvaluationEventType
|
|
||||||
|
|
||||||
|
|
||||||
class EvaluationHistoryService:
|
|
||||||
"""
|
|
||||||
AutoEvaluation va QuickEvaluation uchun history yozuvlarini yaratuvchi servis.
|
|
||||||
Faqat shu servis orqali yoziladi — frontend va boshqa kodlar bu sinfdan foydalanadi.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _build_actor(user) -> dict:
|
|
||||||
if user is None:
|
|
||||||
return {"id": None, "full_name": "Tizim", "role": "system"}
|
|
||||||
full_name = ""
|
|
||||||
if hasattr(user, "get_full_name"):
|
|
||||||
full_name = user.get_full_name().strip()
|
|
||||||
if not full_name and hasattr(user, "phone"):
|
|
||||||
full_name = str(user.phone)
|
|
||||||
return {
|
|
||||||
"id": user.id,
|
|
||||||
"full_name": full_name or str(user),
|
|
||||||
"role": getattr(user, "role", "user"),
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def log_auto(cls, auto_evaluation, event_type: EvaluationEventType, actor=None, meta: dict = None):
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel
|
|
||||||
|
|
||||||
actor_data = cls._build_actor(actor)
|
|
||||||
AutoevaluationhistoryModel.objects.create(
|
|
||||||
auto_evaluation=auto_evaluation,
|
|
||||||
event_type=event_type,
|
|
||||||
actor_id=actor_data["id"],
|
|
||||||
actor_full_name=actor_data["full_name"],
|
|
||||||
actor_role=actor_data["role"],
|
|
||||||
meta=meta or {},
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def log_quick(cls, quick_evaluation, event_type: EvaluationEventType, actor=None, meta: dict = None):
|
|
||||||
from core.apps.evaluation.models import QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
actor_data = cls._build_actor(actor)
|
|
||||||
QuickevaluationhistoryModel.objects.create(
|
|
||||||
quick_evaluation=quick_evaluation,
|
|
||||||
event_type=event_type,
|
|
||||||
actor_id=actor_data["id"],
|
|
||||||
actor_full_name=actor_data["full_name"],
|
|
||||||
actor_role=actor_data["role"],
|
|
||||||
meta=meta or {},
|
|
||||||
)
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,210 +0,0 @@
|
|||||||
from django.db.models.signals import post_save, pre_save
|
|
||||||
from django.dispatch import receiver
|
|
||||||
|
|
||||||
from core.apps.evaluation.choices.auto import AutoEvaluationStatus
|
|
||||||
from core.apps.evaluation.choices.history import EvaluationEventType
|
|
||||||
from core.apps.evaluation.choices.quick import QuickEvaluationStatus
|
|
||||||
from core.apps.evaluation.models import (
|
|
||||||
AutoEvaluationModel,
|
|
||||||
QuickEvaluationModel,
|
|
||||||
ValuationDocumentModel,
|
|
||||||
ValuationModel,
|
|
||||||
)
|
|
||||||
from core.apps.evaluation.services.history import EvaluationHistoryService
|
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
# AutoEvaluation — order_created va status_changed
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=AutoEvaluationModel)
|
|
||||||
def auto_eval_pre_save(sender, instance, **kwargs):
|
|
||||||
"""Status o'zgarishini kuzatish uchun eski qiymatni saqlaydi."""
|
|
||||||
if instance.pk:
|
|
||||||
try:
|
|
||||||
old = AutoEvaluationModel.objects.get(pk=instance.pk)
|
|
||||||
instance._old_status = old.status
|
|
||||||
except AutoEvaluationModel.DoesNotExist:
|
|
||||||
instance._old_status = None
|
|
||||||
else:
|
|
||||||
instance._old_status = None
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=AutoEvaluationModel)
|
|
||||||
def auto_eval_post_save(sender, instance, created, **kwargs):
|
|
||||||
if created:
|
|
||||||
actor = None
|
|
||||||
if instance.valuation_id:
|
|
||||||
try:
|
|
||||||
actor = instance.valuation.created_by
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
EvaluationHistoryService.log_auto(
|
|
||||||
auto_evaluation=instance,
|
|
||||||
event_type=EvaluationEventType.ORDER_CREATED,
|
|
||||||
actor=actor,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
old_status = getattr(instance, "_old_status", None)
|
|
||||||
if old_status is not None and old_status != instance.status:
|
|
||||||
status_labels = dict(AutoEvaluationStatus.choices)
|
|
||||||
EvaluationHistoryService.log_auto(
|
|
||||||
auto_evaluation=instance,
|
|
||||||
event_type=EvaluationEventType.STATUS_CHANGED,
|
|
||||||
meta={
|
|
||||||
"from_status": old_status,
|
|
||||||
"from_status_display": status_labels.get(old_status, old_status),
|
|
||||||
"to_status": instance.status,
|
|
||||||
"to_status_display": status_labels.get(instance.status, instance.status),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
# Valuation — evaluator_assigned (assigned_to o'zgarganda)
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=ValuationModel)
|
|
||||||
def valuation_pre_save(sender, instance, **kwargs):
|
|
||||||
"""assigned_to o'zgarishini kuzatish uchun eski qiymatni saqlaydi."""
|
|
||||||
if instance.pk:
|
|
||||||
try:
|
|
||||||
old = ValuationModel.objects.get(pk=instance.pk)
|
|
||||||
instance._old_assigned_to_id = old.assigned_to_id
|
|
||||||
except ValuationModel.DoesNotExist:
|
|
||||||
instance._old_assigned_to_id = None
|
|
||||||
else:
|
|
||||||
instance._old_assigned_to_id = None
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=ValuationModel)
|
|
||||||
def valuation_post_save(sender, instance, created, **kwargs):
|
|
||||||
if created:
|
|
||||||
return
|
|
||||||
old_assigned_id = getattr(instance, "_old_assigned_to_id", None)
|
|
||||||
if instance.assigned_to_id and old_assigned_id != instance.assigned_to_id:
|
|
||||||
try:
|
|
||||||
auto_eval = instance.auto_detail
|
|
||||||
except AutoEvaluationModel.DoesNotExist:
|
|
||||||
return
|
|
||||||
evaluator = instance.assigned_to
|
|
||||||
evaluator_name = ""
|
|
||||||
if evaluator:
|
|
||||||
evaluator_name = evaluator.get_full_name().strip() or str(evaluator.phone)
|
|
||||||
EvaluationHistoryService.log_auto(
|
|
||||||
auto_evaluation=auto_eval,
|
|
||||||
event_type=EvaluationEventType.EVALUATOR_ASSIGNED,
|
|
||||||
meta={
|
|
||||||
"evaluator_id": instance.assigned_to_id,
|
|
||||||
"evaluator_name": evaluator_name,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
# ValuationDocument — document_uploaded
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
@receiver(post_save, sender=ValuationDocumentModel)
|
|
||||||
def document_post_save(sender, instance, created, **kwargs):
|
|
||||||
if not created:
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
auto_eval = instance.valuation.auto_detail
|
|
||||||
except (AttributeError, AutoEvaluationModel.DoesNotExist):
|
|
||||||
return
|
|
||||||
file_name = ""
|
|
||||||
if instance.file:
|
|
||||||
file_name = instance.file.name.split("/")[-1]
|
|
||||||
EvaluationHistoryService.log_auto(
|
|
||||||
auto_evaluation=auto_eval,
|
|
||||||
event_type=EvaluationEventType.DOCUMENT_UPLOADED,
|
|
||||||
actor=instance.uploaded_by,
|
|
||||||
meta={
|
|
||||||
"document_type": instance.document_type,
|
|
||||||
"document_type_display": instance.get_document_type_display(),
|
|
||||||
"file_name": file_name,
|
|
||||||
"title": instance.title or "",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
# Payment — payment_made (status COMPLETED bo'lganda)
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
@receiver(pre_save, sender="payment.PaymentModel")
|
|
||||||
def payment_pre_save(sender, instance, **kwargs):
|
|
||||||
if instance.pk:
|
|
||||||
try:
|
|
||||||
old = sender.objects.get(pk=instance.pk)
|
|
||||||
instance._old_payment_status = old.status
|
|
||||||
except sender.DoesNotExist:
|
|
||||||
instance._old_payment_status = None
|
|
||||||
else:
|
|
||||||
instance._old_payment_status = None
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender="payment.PaymentModel")
|
|
||||||
def payment_post_save(sender, instance, created, **kwargs):
|
|
||||||
old_status = getattr(instance, "_old_payment_status", None)
|
|
||||||
is_newly_completed = (
|
|
||||||
instance.status == "completed"
|
|
||||||
and (created or old_status != "completed")
|
|
||||||
)
|
|
||||||
if not is_newly_completed:
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
auto_eval = instance.valuation.auto_detail
|
|
||||||
except (AttributeError, AutoEvaluationModel.DoesNotExist):
|
|
||||||
return
|
|
||||||
EvaluationHistoryService.log_auto(
|
|
||||||
auto_evaluation=auto_eval,
|
|
||||||
event_type=EvaluationEventType.PAYMENT_MADE,
|
|
||||||
actor=instance.payer,
|
|
||||||
meta={
|
|
||||||
"amount": str(instance.amount),
|
|
||||||
"payment_method": instance.payment_method,
|
|
||||||
"transaction_id": instance.transaction_id or "",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
# QuickEvaluation — order_created va status_changed
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=QuickEvaluationModel)
|
|
||||||
def quick_eval_pre_save(sender, instance, **kwargs):
|
|
||||||
if instance.pk:
|
|
||||||
try:
|
|
||||||
old = QuickEvaluationModel.objects.get(pk=instance.pk)
|
|
||||||
instance._old_status = old.status
|
|
||||||
except QuickEvaluationModel.DoesNotExist:
|
|
||||||
instance._old_status = None
|
|
||||||
else:
|
|
||||||
instance._old_status = None
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=QuickEvaluationModel)
|
|
||||||
def quick_eval_post_save(sender, instance, created, **kwargs):
|
|
||||||
if created:
|
|
||||||
EvaluationHistoryService.log_quick(
|
|
||||||
quick_evaluation=instance,
|
|
||||||
event_type=EvaluationEventType.ORDER_CREATED,
|
|
||||||
actor=instance.created_by,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
old_status = getattr(instance, "_old_status", None)
|
|
||||||
if old_status is not None and old_status != instance.status:
|
|
||||||
status_labels = dict(QuickEvaluationStatus.choices)
|
|
||||||
EvaluationHistoryService.log_quick(
|
|
||||||
quick_evaluation=instance,
|
|
||||||
event_type=EvaluationEventType.STATUS_CHANGED,
|
|
||||||
meta={
|
|
||||||
"from_status": old_status,
|
|
||||||
"from_status_display": status_labels.get(old_status, old_status),
|
|
||||||
"to_status": instance.status,
|
|
||||||
"to_status_display": status_labels.get(instance.status, instance.status),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
from .test_AutoEvaluationHistory import * # noqa
|
|
||||||
from .test_QuickEvaluationHistory import * # noqa
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from django.urls import reverse
|
|
||||||
from rest_framework.test import APIClient
|
|
||||||
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def instance(db):
|
|
||||||
return AutoevaluationhistoryModel._baker()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def api_client(instance):
|
|
||||||
client = APIClient()
|
|
||||||
##client.force_authenticate(user=instance.user)
|
|
||||||
return client, instance
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def data(api_client):
|
|
||||||
client, instance = api_client
|
|
||||||
return (
|
|
||||||
{
|
|
||||||
"list": reverse("auto-evaluation-history-list"),
|
|
||||||
"retrieve": reverse("auto-evaluation-history-detail", kwargs={"pk": instance.pk}),
|
|
||||||
"retrieve-not-found": reverse("auto-evaluation-history-detail", kwargs={"pk": 1000}),
|
|
||||||
},
|
|
||||||
client,
|
|
||||||
instance,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_list(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["list"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve_not_found(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve-not-found"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert data_resp["status"] is False
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_create(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.post(urls["list"], data={"name": "test"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 201
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_update(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_partial_update():
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_destroy(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.delete(urls["retrieve"])
|
|
||||||
# assert response.status_code == 204
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from django.urls import reverse
|
|
||||||
from rest_framework.test import APIClient
|
|
||||||
|
|
||||||
from core.apps.evaluation.models import QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def instance(db):
|
|
||||||
return QuickevaluationhistoryModel._baker()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def api_client(instance):
|
|
||||||
client = APIClient()
|
|
||||||
##client.force_authenticate(user=instance.user)
|
|
||||||
return client, instance
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def data(api_client):
|
|
||||||
client, instance = api_client
|
|
||||||
return (
|
|
||||||
{
|
|
||||||
"list": reverse("quick-evaluation-history-list"),
|
|
||||||
"retrieve": reverse("quick-evaluation-history-detail", kwargs={"pk": instance.pk}),
|
|
||||||
"retrieve-not-found": reverse("quick-evaluation-history-detail", kwargs={"pk": 1000}),
|
|
||||||
},
|
|
||||||
client,
|
|
||||||
instance,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_list(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["list"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert data_resp["status"] is True
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_retrieve_not_found(data):
|
|
||||||
urls, client, _ = data
|
|
||||||
response = client.get(urls["retrieve-not-found"])
|
|
||||||
data_resp = response.json()
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert data_resp["status"] is False
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_create(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.post(urls["list"], data={"name": "test"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 201
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_update(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_partial_update():
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.patch(urls["retrieve"], data={"name": "updated"})
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
#
|
|
||||||
# # verify updated value
|
|
||||||
# response = client.get(urls["retrieve"])
|
|
||||||
# assert response.json()["status"] is True
|
|
||||||
# assert response.status_code == 200
|
|
||||||
# assert response.json()["data"]["name"] == "updated"
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.django_db
|
|
||||||
# def test_destroy(data):
|
|
||||||
# urls, client, _ = data
|
|
||||||
# response = client.delete(urls["retrieve"])
|
|
||||||
# assert response.status_code == 204
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
from modeltranslation.translator import TranslationOptions, register
|
|
||||||
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
|
|
||||||
|
|
||||||
|
|
||||||
@register(AutoevaluationhistoryModel)
|
|
||||||
class AutoevaluationhistoryTranslation(TranslationOptions):
|
|
||||||
fields = []
|
|
||||||
|
|
||||||
|
|
||||||
@register(QuickevaluationhistoryModel)
|
|
||||||
class QuickevaluationhistoryTranslation(TranslationOptions):
|
|
||||||
fields = []
|
|
||||||
@@ -2,18 +2,12 @@ from django.urls import include, path
|
|||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from .views import (
|
from .views import (
|
||||||
AutoEvaluationHistoryView,
|
|
||||||
AutoEvaluationView,
|
AutoEvaluationView,
|
||||||
CustomerView,
|
CustomerView,
|
||||||
DeterminedValueView,
|
|
||||||
EvaluationPurposeView,
|
|
||||||
EvaluationReportView,
|
EvaluationReportView,
|
||||||
EvaluationrequestView,
|
EvaluationrequestView,
|
||||||
MovablePropertyEvaluationView,
|
MovablePropertyEvaluationView,
|
||||||
OwnershipFormView,
|
|
||||||
PropertyOwnerView,
|
PropertyOwnerView,
|
||||||
PropertyRightsView,
|
|
||||||
QuickEvaluationHistoryView,
|
|
||||||
QuickEvaluationView,
|
QuickEvaluationView,
|
||||||
RealEstateEvaluationView,
|
RealEstateEvaluationView,
|
||||||
ReferenceitemView,
|
ReferenceitemView,
|
||||||
@@ -23,12 +17,6 @@ from .views import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register("auto-evaluation-history", AutoEvaluationHistoryView, basename="auto-evaluation-history")
|
|
||||||
router.register("quick-evaluation-history", QuickEvaluationHistoryView, basename="quick-evaluation-history")
|
|
||||||
router.register("determined-value", DeterminedValueView, basename="determined-value")
|
|
||||||
router.register("evaluation-purpose", EvaluationPurposeView, basename="evaluation-purpose")
|
|
||||||
router.register("property-rights", PropertyRightsView, basename="property-rights")
|
|
||||||
router.register("ownership-form", OwnershipFormView, basename="ownership-form")
|
|
||||||
router.register("evaluation-request", EvaluationrequestView, basename="evaluation-request")
|
router.register("evaluation-request", EvaluationrequestView, basename="evaluation-request")
|
||||||
router.register("reference-item", ReferenceitemView, basename="reference-item")
|
router.register("reference-item", ReferenceitemView, basename="reference-item")
|
||||||
router.register("valuation-document", ValuationDocumentView, basename="valuation-document")
|
router.register("valuation-document", ValuationDocumentView, basename="valuation-document")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
# from django.core.exceptions import ValidationError
|
|
||||||
|
|
||||||
|
|
||||||
class AutoevaluationhistoryValidator:
|
|
||||||
def __init__(self): ...
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class QuickevaluationhistoryValidator:
|
|
||||||
def __init__(self): ...
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
return True
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from .auto import * # noqa
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .document import * # noqa
|
from .document import * # noqa
|
||||||
from .history import * # noqa
|
|
||||||
from .movable import * # noqa
|
from .movable import * # noqa
|
||||||
from .quick import * # noqa
|
from .quick import * # noqa
|
||||||
from .real_estate import * # noqa
|
from .real_estate import * # noqa
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
from django_core.mixins import BaseViewSetMixin
|
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
|
||||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
|
||||||
from rest_framework.filters import OrderingFilter
|
|
||||||
from rest_framework.permissions import AllowAny
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
||||||
|
|
||||||
from core.apps.evaluation.filters.history import (
|
|
||||||
AutoevaluationhistoryFilter,
|
|
||||||
QuickevaluationhistoryFilter,
|
|
||||||
)
|
|
||||||
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
|
|
||||||
from core.apps.evaluation.serializers.history import (
|
|
||||||
CreateAutoevaluationhistorySerializer,
|
|
||||||
CreateQuickevaluationhistorySerializer,
|
|
||||||
ListAutoevaluationhistorySerializer,
|
|
||||||
ListQuickevaluationhistorySerializer,
|
|
||||||
RetrieveAutoevaluationhistorySerializer,
|
|
||||||
RetrieveQuickevaluationhistorySerializer,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["AutoEvaluationHistory"],
|
|
||||||
parameters=[
|
|
||||||
OpenApiParameter("auto_evaluation", int, description="AutoEvaluation ID bo'yicha filter"),
|
|
||||||
OpenApiParameter("event_type", str, description="Event turi bo'yicha filter"),
|
|
||||||
OpenApiParameter("created_from", str, description="Boshlanish sanasi (ISO 8601)"),
|
|
||||||
OpenApiParameter("created_to", str, description="Tugash sanasi (ISO 8601)"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
class AutoEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
|
||||||
# select_related("auto_evaluation") faqat retrieve uchun — list uchun kerak emas
|
|
||||||
queryset = AutoevaluationhistoryModel.objects.only(
|
|
||||||
"id", "auto_evaluation_id", "event_type",
|
|
||||||
"actor_id", "actor_full_name", "actor_role",
|
|
||||||
"meta", "created_at",
|
|
||||||
)
|
|
||||||
serializer_class = ListAutoevaluationhistorySerializer
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, OrderingFilter]
|
|
||||||
filterset_class = AutoevaluationhistoryFilter
|
|
||||||
ordering_fields = ["created_at"]
|
|
||||||
ordering = ["created_at"]
|
|
||||||
|
|
||||||
action_permission_classes = {}
|
|
||||||
action_serializer_class = {
|
|
||||||
"list": ListAutoevaluationhistorySerializer,
|
|
||||||
"retrieve": RetrieveAutoevaluationhistorySerializer,
|
|
||||||
"create": CreateAutoevaluationhistorySerializer,
|
|
||||||
}
|
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
|
||||||
# Queryset bir marta evaluate qilinadi — COUNT uchun alohida query yo'q
|
|
||||||
results = list(queryset)
|
|
||||||
serializer = self.get_serializer(results, many=True)
|
|
||||||
return Response({
|
|
||||||
"count": len(results),
|
|
||||||
"next": None,
|
|
||||||
"previous": None,
|
|
||||||
"results": serializer.data,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(
|
|
||||||
tags=["QuickEvaluationHistory"],
|
|
||||||
parameters=[
|
|
||||||
OpenApiParameter("quick_evaluation", int, description="QuickEvaluation ID bo'yicha filter"),
|
|
||||||
OpenApiParameter("event_type", str, description="Event turi bo'yicha filter"),
|
|
||||||
OpenApiParameter("created_from", str, description="Boshlanish sanasi (ISO 8601)"),
|
|
||||||
OpenApiParameter("created_to", str, description="Tugash sanasi (ISO 8601)"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
class QuickEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
|
||||||
queryset = QuickevaluationhistoryModel.objects.only(
|
|
||||||
"id", "quick_evaluation_id", "event_type",
|
|
||||||
"actor_id", "actor_full_name", "actor_role",
|
|
||||||
"meta", "created_at",
|
|
||||||
)
|
|
||||||
serializer_class = ListQuickevaluationhistorySerializer
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, OrderingFilter]
|
|
||||||
filterset_class = QuickevaluationhistoryFilter
|
|
||||||
ordering_fields = ["created_at"]
|
|
||||||
ordering = ["created_at"]
|
|
||||||
|
|
||||||
action_permission_classes = {}
|
|
||||||
action_serializer_class = {
|
|
||||||
"list": ListQuickevaluationhistorySerializer,
|
|
||||||
"retrieve": RetrieveQuickevaluationhistorySerializer,
|
|
||||||
"create": CreateQuickevaluationhistorySerializer,
|
|
||||||
}
|
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
|
||||||
results = list(queryset)
|
|
||||||
serializer = self.get_serializer(results, many=True)
|
|
||||||
return Response({
|
|
||||||
"count": len(results),
|
|
||||||
"next": None,
|
|
||||||
"previous": None,
|
|
||||||
"results": serializer.data,
|
|
||||||
})
|
|
||||||
@@ -11,72 +11,9 @@ from core.apps.evaluation.serializers.reference import (
|
|||||||
CreateReferenceitemSerializer,
|
CreateReferenceitemSerializer,
|
||||||
ListReferenceitemSerializer,
|
ListReferenceitemSerializer,
|
||||||
RetrieveReferenceitemSerializer,
|
RetrieveReferenceitemSerializer,
|
||||||
EvaluationPurposeSerializer,
|
|
||||||
DeterminedValueSerializer,
|
|
||||||
LabelValueSerializer,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["EvaluationPurpose"])
|
|
||||||
class EvaluationPurposeView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
|
||||||
queryset = ReferenceitemModel.objects.filter(
|
|
||||||
type="evaluation_purpose", is_active=True
|
|
||||||
).order_by("order", "name")
|
|
||||||
serializer_class = EvaluationPurposeSerializer
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
|
||||||
search_fields = ["name"]
|
|
||||||
ordering_fields = ["name", "order"]
|
|
||||||
ordering = ["order", "name"]
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["DeterminedValue"])
|
|
||||||
class DeterminedValueView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
|
||||||
queryset = ReferenceitemModel.objects.filter(
|
|
||||||
type="determined_value", is_active=True
|
|
||||||
).order_by("order", "name")
|
|
||||||
serializer_class = DeterminedValueSerializer
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
|
||||||
search_fields = ["name"]
|
|
||||||
ordering_fields = ["name", "order"]
|
|
||||||
ordering = ["order", "name"]
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["PropertyRights"])
|
|
||||||
class PropertyRightsView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
|
||||||
queryset = ReferenceitemModel.objects.filter(
|
|
||||||
type="property_rights", is_active=True
|
|
||||||
).order_by("order", "name")
|
|
||||||
serializer_class = LabelValueSerializer
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
|
||||||
search_fields = ["name"]
|
|
||||||
ordering_fields = ["name", "order"]
|
|
||||||
ordering = ["order", "name"]
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["OwnershipForm"])
|
|
||||||
class OwnershipFormView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
|
||||||
queryset = ReferenceitemModel.objects.filter(
|
|
||||||
type="ownership_form", is_active=True
|
|
||||||
).order_by("order", "name")
|
|
||||||
serializer_class = LabelValueSerializer
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
pagination_class = None
|
|
||||||
|
|
||||||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
|
||||||
search_fields = ["name"]
|
|
||||||
ordering_fields = ["name", "order"]
|
|
||||||
ordering = ["order", "name"]
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(tags=["ReferenceItem"])
|
@extend_schema(tags=["ReferenceItem"])
|
||||||
class ReferenceitemView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
class ReferenceitemView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||||
queryset = ReferenceitemModel.objects.select_related("parent").filter(is_active=True)
|
queryset = ReferenceitemModel.objects.select_related("parent").filter(is_active=True)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ services:
|
|||||||
max-file: "5"
|
max-file: "5"
|
||||||
|
|
||||||
web:
|
web:
|
||||||
image: husanjon/sifatbaho:59
|
image: husanjon/sifatbaho:46
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
Reference in New Issue
Block a user