aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-20 15:01:20 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-20 15:01:20 +0100
commite4c95417112ffe8ba684b4f1d7bd957f87b2f2ed (patch)
tree9b61947660b28196dc7f33df42c82dc1c7ffd979 /ctrack/organisations/views.py
parent4ea13b2ed79e95d2cf710c8d2d6e95fb454e054a (diff)
func to group lead inspectors by submode
Diffstat (limited to 'ctrack/organisations/views.py')
-rw-r--r--ctrack/organisations/views.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index fa811eb..45a86bb 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -1,5 +1,5 @@
import itertools
-from typing import Any
+from typing import Any, Dict, List, Set
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import transaction
@@ -11,8 +11,9 @@ from django.views.generic import CreateView, DetailView, FormView, ListView
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
+from .models import IncidentReport, Organisation, Person, Submode
from .utils import filter_private_events
@@ -142,3 +143,18 @@ 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, List[str]]:
+ 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] = list(insp)
+ del insp
+ return out