diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-20 15:57:26 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-20 15:57:26 +0100 |
commit | 30d2bf6d91e625d08c38800d1b1819d90dfe7f1e (patch) | |
tree | d310a7d569c1449d419329a08f327129c23002c3 /ctrack/organisations/utils.py | |
parent | 98f6ce0fa2ce5692f578a98922f50aa79fd46bdd (diff) |
poor implementation of lead and deputy inspectors by submode on home page
Diffstat (limited to '')
-rw-r--r-- | ctrack/organisations/utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
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 |