133 lines
No EOL
4.6 KiB
Python
133 lines
No EOL
4.6 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
from .models import (
|
|
Control, Category, ControlCheck, DocumentCheck, CheckList,
|
|
CheckListControlCheck, CheckListDocumentCheck, Remark, RemarkImage,
|
|
RemarkTag, ControlReport, ControlReferencePlan, ControlReportTemplate
|
|
)
|
|
from common.private_files.helpers import build_private_url
|
|
|
|
@admin.register(Control)
|
|
class ControlAdmin(admin.ModelAdmin):
|
|
list_display = ("control_code", "control_type", "status", "project", "phase", "control_author", "updated_at")
|
|
list_filter = ("status", "control_type", "project", "phase", "interventions")
|
|
search_fields = ("control_code", "description", "location", "control_author__username")
|
|
ordering = ("-updated_at",)
|
|
autocomplete_fields = ["project", "phase", "interventions", "control_author"]
|
|
|
|
|
|
@admin.register(Category)
|
|
class CategoryAdmin(admin.ModelAdmin):
|
|
list_display = ("cat_code", "get_name", "thematic")
|
|
search_fields = ("cat_code", "name_fr", "name_nl")
|
|
list_filter = ("thematic",)
|
|
|
|
|
|
@admin.register(ControlCheck)
|
|
class ControlCheckAdmin(admin.ModelAdmin):
|
|
list_display = ("control", "category", "status")
|
|
list_filter = ("status", "category")
|
|
autocomplete_fields = ["control", "category"]
|
|
|
|
|
|
@admin.register(DocumentCheck)
|
|
class DocumentCheckAdmin(admin.ModelAdmin):
|
|
list_display = ("control", "doc_type", "status")
|
|
list_filter = ("status", "doc_type")
|
|
autocomplete_fields = ["control"]
|
|
|
|
|
|
@admin.register(CheckList)
|
|
class CheckListAdmin(admin.ModelAdmin):
|
|
list_display = ("checklist_code", "get_name", "thematic")
|
|
search_fields = ("checklist_code", "name_fr", "name_nl")
|
|
list_filter = ("thematic",)
|
|
|
|
|
|
@admin.register(CheckListControlCheck)
|
|
class CheckListControlCheckAdmin(admin.ModelAdmin):
|
|
list_display = ("checklist", "category")
|
|
autocomplete_fields = ["checklist", "category"]
|
|
|
|
|
|
@admin.register(CheckListDocumentCheck)
|
|
class CheckListDocumentCheckAdmin(admin.ModelAdmin):
|
|
list_display = ("checklist", "doc_type")
|
|
list_filter = ("doc_type",)
|
|
autocomplete_fields = ["checklist"]
|
|
|
|
|
|
@admin.register(Remark)
|
|
class RemarkAdmin(admin.ModelAdmin):
|
|
list_display = ("control", "remark_number", "description", "internal", "status", "created_at", "updated_at")
|
|
list_filter = ("status", "internal")
|
|
search_fields = ("description",)
|
|
autocomplete_fields = ["control"]
|
|
|
|
|
|
@admin.register(RemarkImage)
|
|
class RemarkImageAdmin(admin.ModelAdmin):
|
|
list_display = ("remark", "file")
|
|
autocomplete_fields = ["remark"]
|
|
|
|
|
|
@admin.register(RemarkTag)
|
|
class RemarkTagAdmin(admin.ModelAdmin):
|
|
list_display = ("remark", "category")
|
|
autocomplete_fields = ["remark", "category"]
|
|
|
|
|
|
@admin.register(ControlReport)
|
|
class ControlReportAdmin(admin.ModelAdmin):
|
|
list_display = ("control", "created_at", "created_by", "status", "document")
|
|
list_filter = ("status",)
|
|
search_fields = ("control__control_code",)
|
|
autocomplete_fields = ["control", "created_by"]
|
|
|
|
|
|
@admin.register(ControlReferencePlan)
|
|
class ControlReferencePlanAdmin(admin.ModelAdmin):
|
|
# Liste des champs à afficher dans la liste des objets
|
|
list_display = ('name', 'control', 'uploaded_by', 'plan_preview', 'max_x', 'max_y', 'uploaded_at')
|
|
|
|
# Filtres pour faciliter la navigation
|
|
list_filter = ('control', 'uploaded_by')
|
|
|
|
# Champs de recherche
|
|
search_fields = ('name', 'control__name', 'uploaded_by__username')
|
|
|
|
# Champs en lecture seule (si nécessaire)
|
|
readonly_fields = ('max_x', 'max_y', 'uploaded_at', 'plan_preview')
|
|
|
|
# Personnalisation du formulaire d'édition
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('control', 'name', 'plan', 'plan_preview', 'uploaded_by', 'uploaded_at')
|
|
}),
|
|
('Dimensions normalisées', {
|
|
'fields': ('max_x', 'max_y'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
@admin.display(description='Plan')
|
|
def plan_preview(self, obj):
|
|
if not obj.plan:
|
|
return '-'
|
|
url = build_private_url('controls', 'ControlReferencePlan', obj.pk, 'plan')
|
|
return format_html(
|
|
'<a href="{}" target="_blank"><img src="{}" style="max-height:80px;max-width:120px;" /></a>',
|
|
url, url
|
|
)
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
obj.uploaded_by = request.user # Associer l'utilisateur connecté
|
|
super().save_model(request, obj, form, change)
|
|
|
|
|
|
|
|
@admin.register(ControlReportTemplate)
|
|
class ControlReportTemplateAdmin(admin.ModelAdmin):
|
|
list_display = ("id", "control", "name", "updated_by", "updated_at")
|
|
search_fields = ("control__description",)
|
|
autocomplete_fields = ["control"] |