246 lines
6.1 KiB
Python
246 lines
6.1 KiB
Python
from django.contrib.gis import admin
|
|
|
|
from .models import (
|
|
ComplementaryPoliceRegulation,
|
|
Organization,
|
|
RegulationArticle,
|
|
RegulationMeasurePanel,
|
|
SignPanel,
|
|
SignPanelModel,
|
|
SignPanelType,
|
|
SignPanelTypeArticle,
|
|
SignPole,
|
|
SignPoleModel,
|
|
SignStreet,
|
|
SignStreetDocument,
|
|
)
|
|
|
|
|
|
@admin.register(Organization)
|
|
class OrganizationAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"name_fr",
|
|
"name_nl",
|
|
"code",
|
|
"organization_type",
|
|
"is_active",
|
|
"created_at",
|
|
)
|
|
search_fields = ("name_fr", "name_nl", "code", "description")
|
|
list_filter = ("organization_type", "is_active")
|
|
ordering = ("name_fr",)
|
|
|
|
|
|
@admin.register(SignStreet)
|
|
class SignStreetAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"code",
|
|
"name_fr",
|
|
"name_nl",
|
|
"municipality",
|
|
"road_code",
|
|
"section_code",
|
|
"street_level",
|
|
)
|
|
search_fields = ("code", "name_fr", "name_nl", "road_code", "section_code")
|
|
list_filter = ("municipality",)
|
|
|
|
|
|
@admin.register(SignStreetDocument)
|
|
class SignStreetDocumentAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"street",
|
|
"document_type",
|
|
"uploaded_by",
|
|
"organization",
|
|
"upload_date",
|
|
)
|
|
search_fields = (
|
|
"street__code",
|
|
"street__name_fr",
|
|
"street__name_nl",
|
|
"uploaded_by__username",
|
|
)
|
|
list_filter = ("document_type", "organization")
|
|
list_select_related = ("street", "organization", "uploaded_by")
|
|
|
|
|
|
@admin.register(SignPoleModel)
|
|
class SignPoleModelAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"code",
|
|
"name_fr",
|
|
"name_nl",
|
|
"category",
|
|
"material",
|
|
"color",
|
|
"height",
|
|
"diameter",
|
|
)
|
|
search_fields = ("code", "name_fr", "name_nl", "material", "color", "ral")
|
|
list_filter = ("category", "material", "color")
|
|
|
|
|
|
@admin.register(SignPole)
|
|
class SignPoleAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"code",
|
|
"model",
|
|
"street",
|
|
"organization",
|
|
"status",
|
|
"installation_date",
|
|
)
|
|
search_fields = (
|
|
"code",
|
|
"model__name_fr",
|
|
"model__name_nl",
|
|
"street__code",
|
|
"street__name_fr",
|
|
"street__name_nl",
|
|
)
|
|
list_filter = ("status", "organization", "model")
|
|
list_select_related = ("model", "street", "organization")
|
|
|
|
|
|
@admin.register(SignPanelModel)
|
|
class SignPanelModelAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"code",
|
|
"name_fr",
|
|
"name_nl",
|
|
"category",
|
|
"shape",
|
|
"material",
|
|
"color",
|
|
"width",
|
|
"height",
|
|
"diameter",
|
|
)
|
|
search_fields = ("code", "name_fr", "name_nl", "material", "color", "shape", "ral")
|
|
list_filter = ("category", "shape", "material", "color")
|
|
|
|
|
|
@admin.register(SignPanelType)
|
|
class SignPanelTypeAdmin(admin.ModelAdmin):
|
|
list_display = ("code", "name_fr", "name_nl", "default_width", "default_height", "default_diameter")
|
|
search_fields = ("code", "name_fr", "name_nl", "description")
|
|
|
|
|
|
class SignPanelTypeArticleInline(admin.TabularInline):
|
|
model = SignPanelTypeArticle
|
|
extra = 0
|
|
fields = ("article",)
|
|
autocomplete_fields = ("article",)
|
|
verbose_name = "Article applicable"
|
|
verbose_name_plural = "Articles applicables"
|
|
|
|
|
|
@admin.register(RegulationArticle)
|
|
class RegulationArticleAdmin(admin.ModelAdmin):
|
|
list_display = ("article_id", "level", "parent", "text_fr_short")
|
|
search_fields = ("article_id", "text_fr", "text_nl")
|
|
list_filter = ("level",)
|
|
list_select_related = ("parent",)
|
|
ordering = ("ordering", "article_id")
|
|
|
|
def text_fr_short(self, obj):
|
|
return (obj.text_fr or "")[:100]
|
|
text_fr_short.short_description = "Texte FR"
|
|
|
|
|
|
@admin.register(SignPanelTypeArticle)
|
|
class SignPanelTypeArticleAdmin(admin.ModelAdmin):
|
|
list_display = ("panel_type", "article")
|
|
search_fields = ("panel_type__code", "article__article_id", "article__text_fr")
|
|
list_filter = ("panel_type",)
|
|
list_select_related = ("panel_type", "article")
|
|
autocomplete_fields = ("panel_type", "article")
|
|
|
|
|
|
@admin.register(SignPanel)
|
|
class SignPanelAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"code",
|
|
"signpanel_type",
|
|
"model",
|
|
"pole",
|
|
"street",
|
|
"organization",
|
|
"support_type",
|
|
"is_temporary",
|
|
"status",
|
|
)
|
|
search_fields = (
|
|
"code",
|
|
"model__name_fr",
|
|
"model__name_nl",
|
|
"signpanel_type__code",
|
|
"pole__code",
|
|
"street__code",
|
|
"street__name_fr",
|
|
"street__name_nl",
|
|
)
|
|
list_filter = (
|
|
"support_type",
|
|
"is_temporary",
|
|
"organization",
|
|
"model",
|
|
"signpanel_type",
|
|
"status",
|
|
)
|
|
list_select_related = ("model", "signpanel_type", "pole", "street", "organization")
|
|
|
|
|
|
class ComplementaryPoliceRegulationPanelReadOnlyInline(admin.TabularInline):
|
|
model = ComplementaryPoliceRegulation.panels.through
|
|
extra = 0
|
|
fields = ("signpanel_link",)
|
|
readonly_fields = ("signpanel_link",)
|
|
can_delete = False
|
|
verbose_name = "Panneau associé"
|
|
verbose_name_plural = "Panneaux associés"
|
|
|
|
def signpanel_link(self, obj):
|
|
"""Affiche un lien vers le panneau"""
|
|
from django.urls import reverse
|
|
from django.utils.html import format_html
|
|
if obj.signpanel:
|
|
url = reverse("admin:sign_signpanel_change", args=[obj.signpanel.id])
|
|
return format_html('<a href="{}">{}</a>', url, obj.signpanel.code)
|
|
return "-"
|
|
signpanel_link.short_description = "Panneau"
|
|
|
|
|
|
@admin.register(ComplementaryPoliceRegulation)
|
|
class ComplementaryPoliceRegulationAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "reference", "status", "decision_date", "organization")
|
|
search_fields = ("title", "reference", "organization__name_fr", "organization__name_nl")
|
|
list_filter = ("status", "decision_date", "organization")
|
|
inlines = [ComplementaryPoliceRegulationPanelReadOnlyInline]
|
|
exclude = ("panels",)
|
|
autocomplete_fields = ("abrogated_panels", "selected_articles", "selected_abrogation_articles")
|
|
|
|
|
|
class RegulationMeasurePanelInline(admin.TabularInline):
|
|
model = RegulationMeasurePanel
|
|
extra = 0
|
|
fields = ("regulation", "article", "section", "panel")
|
|
autocomplete_fields = ("article", "panel")
|
|
verbose_name = "Panneau de mesure"
|
|
verbose_name_plural = "Panneaux de mesures"
|
|
|
|
|
|
@admin.register(RegulationMeasurePanel)
|
|
class RegulationMeasurePanelAdmin(admin.ModelAdmin):
|
|
list_display = ("regulation", "article", "section", "panel")
|
|
search_fields = (
|
|
"regulation__title",
|
|
"regulation__reference",
|
|
"article__article_id",
|
|
"article__text_fr",
|
|
"panel__code",
|
|
)
|
|
list_filter = ("section", "regulation", "article")
|
|
list_select_related = ("regulation", "article", "panel")
|
|
autocomplete_fields = ("article", "panel")
|