aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/admin.py
blob: 5cb5bb4e80024a4fd4efd983e0cfd6a8263c6086 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from django.contrib import admin

from ctrack.caf.models import CAF, EssentialService

from .models import (
    Address,
    AddressType,
    IncidentReport,
    Mode,
    Organisation,
    Person,
    Role,
    Stakeholder,
    Submode,
)


# So we can get the organisation name - a reverse lookup
def get_organisation_name(person):
    return Organisation.objects.filter(person__id=person.id).first().name


def get_first_caf(org):
    return CAF.objects.filter(organisation__id=org.id).first().version


# We need this to ensure the column header in the admin does't read the func name
get_organisation_name.short_description = "Organisation"


class IncidentReportAdmin(admin.ModelAdmin):
    model = IncidentReport
    readonly_fields = ["date_time_incident_reported"]


class AddressTypeAdmin(admin.ModelAdmin):
    pass


class StakeholderAdmin(admin.ModelAdmin):
    model = Stakeholder


class AddressInLine(admin.StackedInline):
    model = Address
    max_num = 3
    extra = 1


class EssentialServiceInline(admin.StackedInline):
    model = EssentialService
    max_num = 3
    extra = 1


class OrganisationAdmin(admin.ModelAdmin):
    inlines = [AddressInLine, EssentialServiceInline]
    list_display = (
        "name",
        "submode",
        "date_updated",
        "lead_inspector",
        "deputy_lead_inspector",
    )


class PersonAdmin(admin.ModelAdmin):
    model = Person
    list_display = [
        "first_name",
        "last_name",
        "job_title",
        get_organisation_name,
        "email",
        "mobile",
    ]


class RoleAdmin(admin.ModelAdmin):
    model = Role


class ModeAdmin(admin.ModelAdmin):
    model = Mode


class SubmodeAdmin(admin.ModelAdmin):
    model = Submode


# Register your models here.
admin.site.register(Organisation, OrganisationAdmin)
admin.site.register(AddressType, AddressTypeAdmin)
admin.site.register(Role, RoleAdmin)
admin.site.register(Person, PersonAdmin)
admin.site.register(Mode, ModeAdmin)
admin.site.register(Submode, SubmodeAdmin)
admin.site.register(Stakeholder, StakeholderAdmin)
admin.site.register(IncidentReport, IncidentReportAdmin)