Spaces:
Sleeping
Sleeping
Upload backend/hue_portal/core/admin.py with huggingface_hub
Browse files
backend/hue_portal/core/admin.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
from .models import (
|
| 3 |
+
Procedure,
|
| 4 |
+
Fine,
|
| 5 |
+
Office,
|
| 6 |
+
Advisory,
|
| 7 |
+
Synonym,
|
| 8 |
+
LegalDocument,
|
| 9 |
+
LegalSection,
|
| 10 |
+
LegalDocumentImage,
|
| 11 |
+
IngestionJob,
|
| 12 |
+
SystemAlert,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
@admin.register(Procedure)
|
| 16 |
+
class ProcedureAdmin(admin.ModelAdmin):
|
| 17 |
+
list_display = ("id", "title", "domain", "level", "updated_at")
|
| 18 |
+
search_fields = ("title", "conditions", "dossier")
|
| 19 |
+
list_filter = ("domain", "level")
|
| 20 |
+
|
| 21 |
+
@admin.register(Fine)
|
| 22 |
+
class FineAdmin(admin.ModelAdmin):
|
| 23 |
+
list_display = ("id", "code", "name", "decree")
|
| 24 |
+
search_fields = ("code", "name", "article")
|
| 25 |
+
|
| 26 |
+
@admin.register(Office)
|
| 27 |
+
class OfficeAdmin(admin.ModelAdmin):
|
| 28 |
+
list_display = ("id", "unit_name", "district", "phone")
|
| 29 |
+
search_fields = ("unit_name", "address", "district")
|
| 30 |
+
list_filter = ("district",)
|
| 31 |
+
|
| 32 |
+
@admin.register(Advisory)
|
| 33 |
+
class AdvisoryAdmin(admin.ModelAdmin):
|
| 34 |
+
list_display = ("id", "title", "published_at")
|
| 35 |
+
search_fields = ("title", "summary")
|
| 36 |
+
|
| 37 |
+
@admin.register(Synonym)
|
| 38 |
+
class SynonymAdmin(admin.ModelAdmin):
|
| 39 |
+
list_display = ("id", "keyword", "alias")
|
| 40 |
+
search_fields = ("keyword", "alias")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@admin.register(LegalDocument)
|
| 44 |
+
class LegalDocumentAdmin(admin.ModelAdmin):
|
| 45 |
+
list_display = ("id", "code", "title", "doc_type", "issued_at")
|
| 46 |
+
search_fields = ("code", "title", "summary", "issued_by")
|
| 47 |
+
list_filter = ("doc_type", "issued_by")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@admin.register(LegalSection)
|
| 51 |
+
class LegalSectionAdmin(admin.ModelAdmin):
|
| 52 |
+
list_display = ("id", "document", "section_code", "level", "order")
|
| 53 |
+
list_filter = ("level",)
|
| 54 |
+
search_fields = ("section_code", "section_title", "content")
|
| 55 |
+
autocomplete_fields = ("document",)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
@admin.register(LegalDocumentImage)
|
| 59 |
+
class LegalDocumentImageAdmin(admin.ModelAdmin):
|
| 60 |
+
list_display = ("id", "document", "page_number", "width", "height")
|
| 61 |
+
search_fields = ("document__code", "description")
|
| 62 |
+
list_filter = ("page_number",)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
from .tasks import process_ingestion_job
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
@admin.register(IngestionJob)
|
| 69 |
+
class IngestionJobAdmin(admin.ModelAdmin):
|
| 70 |
+
list_display = ("id", "code", "status", "filename", "created_at", "finished_at")
|
| 71 |
+
search_fields = ("code", "filename", "error_message")
|
| 72 |
+
list_filter = ("status", "created_at")
|
| 73 |
+
autocomplete_fields = ("document",)
|
| 74 |
+
readonly_fields = ("storage_path", "error_message", "stats")
|
| 75 |
+
actions = ["retry_jobs"]
|
| 76 |
+
|
| 77 |
+
@admin.action(description="Retry selected ingestion jobs")
|
| 78 |
+
def retry_jobs(self, request, queryset):
|
| 79 |
+
for job in queryset:
|
| 80 |
+
job.status = job.STATUS_PENDING
|
| 81 |
+
job.progress = 0
|
| 82 |
+
job.error_message = ""
|
| 83 |
+
job.save(update_fields=["status", "progress", "error_message", "updated_at"])
|
| 84 |
+
process_ingestion_job.delay(str(job.id))
|
| 85 |
+
self.message_user(request, f"Đã requeue {queryset.count()} tác vụ")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@admin.register(SystemAlert)
|
| 89 |
+
class SystemAlertAdmin(admin.ModelAdmin):
|
| 90 |
+
list_display = ("id", "alert_type", "title", "severity", "created_at", "resolved_at")
|
| 91 |
+
search_fields = ("title", "message")
|
| 92 |
+
list_filter = ("alert_type", "severity", "resolved_at", "created_at")
|
| 93 |
+
readonly_fields = ("created_at",)
|
| 94 |
+
date_hierarchy = "created_at"
|