158 lines
4.2 KiB
Python
158 lines
4.2 KiB
Python
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,
|
|
)
|