From e4c95417112ffe8ba684b4f1d7bd957f87b2f2ed Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 20 Oct 2020 15:01:20 +0100 Subject: func to group lead inspectors by submode --- ctrack/organisations/views.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'ctrack/organisations/views.py') 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 -- cgit v1.2.3