aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations
diff options
context:
space:
mode:
Diffstat (limited to 'ctrack/organisations')
-rw-r--r--ctrack/organisations/admin.py8
-rw-r--r--ctrack/organisations/templates/organisations/organisation_list.html2
-rw-r--r--ctrack/organisations/utils.py23
-rw-r--r--ctrack/organisations/views.py22
4 files changed, 33 insertions, 22 deletions
diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py
index 02b02ef..5cb5bb4 100644
--- a/ctrack/organisations/admin.py
+++ b/ctrack/organisations/admin.py
@@ -55,7 +55,13 @@ class EssentialServiceInline(admin.StackedInline):
class OrganisationAdmin(admin.ModelAdmin):
inlines = [AddressInLine, EssentialServiceInline]
- list_display = ("name", "submode", "date_updated")
+ list_display = (
+ "name",
+ "submode",
+ "date_updated",
+ "lead_inspector",
+ "deputy_lead_inspector",
+ )
class PersonAdmin(admin.ModelAdmin):
diff --git a/ctrack/organisations/templates/organisations/organisation_list.html b/ctrack/organisations/templates/organisations/organisation_list.html
index 3464308..a45cae8 100644
--- a/ctrack/organisations/templates/organisations/organisation_list.html
+++ b/ctrack/organisations/templates/organisations/organisation_list.html
@@ -45,7 +45,7 @@
<tr>
<td><a href="{% url "organisations:detail" org.slug %}">{{ org.name }}</a></td>
<td>{{ org.submode }}</td>
- <td>{{ org.lead_inspector }}</td>
+ <td>{{ org.lead_inspector.name }}</td>
<td>
{% if org.primary_contacts %}
<ul style="list-style-type:none; float:left; padding: 0">
diff --git a/ctrack/organisations/utils.py b/ctrack/organisations/utils.py
index 121a694..6cc973a 100644
--- a/ctrack/organisations/utils.py
+++ b/ctrack/organisations/utils.py
@@ -1,6 +1,10 @@
+from typing import Dict, Set
+
from django.contrib.auth.models import User
from django.db.models import QuerySet, Q
+from ctrack.organisations.models import Submode
+
def filter_private_events(events: QuerySet, user: User):
"""
@@ -11,3 +15,22 @@ def filter_private_events(events: QuerySet, user: User):
events for the logged-in user.
"""
return events.exclude(~Q(user=user) & Q(private=True))
+
+
+def inspectors_for_each_mode(lead_type="lead_inspector") -> Dict[str, Set[str]]:
+ """
+ We want to be able to group lead inspectors by submode.
+ """
+ if lead_type not in ["lead_inspector", "deputy_lead_inspector"]:
+ raise ValueError("Can only query for lead_inspector and deputy_lead_inspector attributes.")
+ submodes = Submode.objects.all()
+ out = {}
+ for sm in submodes:
+ insp = set()
+ orgs = sm.organisation_set.all()
+ for org in orgs:
+ insp.add(getattr(org, lead_type))
+ insp = {x for x in insp if x is not None}
+ out[sm.descriptor] = insp
+ del insp
+ return out
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index 82347e6..ae98305 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -1,5 +1,5 @@
import itertools
-from typing import Any, Dict, List, Set
+from typing import Any
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import transaction
@@ -13,7 +13,7 @@ from ctrack.caf.models import CAF, EssentialService
from ctrack.register.models import EngagementEvent
from .forms import AddressInlineFormSet, IncidentReportForm, OrganisationCreateForm
-from .models import IncidentReport, Organisation, Person, Submode
+from .models import IncidentReport, Organisation, Person
from .utils import filter_private_events
@@ -143,21 +143,3 @@ class IncidentReportCreateView(FormView):
def form_valid(self, form):
form.save()
return HttpResponseRedirect(reverse("core:home"))
-
-
-def inspectors_for_each_mode(lead_type="lead_inspector") -> Dict[str, Set[str]]:
- """
- We want to be able to group lead inspectors by submode.
- """
- if lead_type not in ["lead_inspector", "deputy_lead_inspector"]:
- raise ValueError("Can only query for lead_inspector and deputy_lead_inspector attributes.")
- submodes = Submode.objects.all()
- out = {}
- for sm in submodes:
- insp = set()
- orgs = sm.organisation_set.all()
- for org in orgs:
- insp.add(getattr(org, lead_type))
- out[sm.descriptor] = insp
- del insp
- return out