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 | |
parent | 98f6ce0fa2ce5692f578a98922f50aa79fd46bdd (diff) |
poor implementation of lead and deputy inspectors by submode on home page
-rw-r--r-- | ctrack/core/tests/test_views.py | 2 | ||||
-rw-r--r-- | ctrack/core/views.py | 5 | ||||
-rw-r--r-- | ctrack/organisations/admin.py | 8 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_list.html | 2 | ||||
-rw-r--r-- | ctrack/organisations/utils.py | 23 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 22 | ||||
-rw-r--r-- | ctrack/templates/pages/home.html | 22 |
7 files changed, 56 insertions, 28 deletions
diff --git a/ctrack/core/tests/test_views.py b/ctrack/core/tests/test_views.py index 9f7d292..dde7b81 100644 --- a/ctrack/core/tests/test_views.py +++ b/ctrack/core/tests/test_views.py @@ -1,7 +1,7 @@ import pytest from ctrack.organisations.models import Organisation, Submode, Mode -from ctrack.organisations.views import inspectors_for_each_mode +from ctrack.organisations.utils import inspectors_for_each_mode from ctrack.organisations.tests.factories import OrganisationFactory pytestmark = pytest.mark.django_db diff --git a/ctrack/core/views.py b/ctrack/core/views.py index 499aedd..5268f66 100644 --- a/ctrack/core/views.py +++ b/ctrack/core/views.py @@ -3,6 +3,7 @@ from django.shortcuts import render from ctrack.caf.models import EssentialService, CAF, ApplicableSystem from ctrack.organisations.models import IncidentReport, Organisation, Person, Submode +from ctrack.organisations.utils import inspectors_for_each_mode from ctrack.register.models import EngagementEvent @@ -33,6 +34,8 @@ def home_page(request): no_essential_services = EssentialService.objects.count() no_systems = ApplicableSystem.objects.count() submodes = Submode.objects.all().order_by("descriptor") + submode_inspector_dict = inspectors_for_each_mode("lead_inspector") + submode_deputy_inspector_dict = inspectors_for_each_mode("deputy_lead_inspector") context = { "no_orgs": no_orgs, "no_people": no_people, @@ -41,5 +44,7 @@ def home_page(request): "no_systems": no_systems, "caf_users": caf_users, "submodes": submodes, + "submode_inspector_dict": submode_inspector_dict, + "submode_deputy_inspector_dict": submode_deputy_inspector_dict, } return render(request, "pages/home.html", context) 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 diff --git a/ctrack/templates/pages/home.html b/ctrack/templates/pages/home.html index 1a3348f..69a306f 100644 --- a/ctrack/templates/pages/home.html +++ b/ctrack/templates/pages/home.html @@ -90,14 +90,26 @@ </svg> Inspectors </h3> - <ul class="list-group"> - {% for submode in submodes %} - {{ submode }} - {% endfor %} - + <p>Inspectors are allocated to an organisation and can therefore be grouped by + the sector that organisation belongs to. This usually means there is one lead + inspector for each submode, but it is possible for an inspector to lead for an + organistion in another sector. The applies for deputy inspector roles.</p> + <h5>Lead Inspectors</h5> + <ul> + {% for k, v in submode_inspector_dict.items %} + <li><strong>{{ k }}</strong> {% for x in v %} {{ x.name }}{% endfor %}</li> + {% endfor %} + </ul> + <h5>Deputy Lead Inspectors</h5> + <ul> + {% for k, v in submode_deputy_inspector_dict.items %} + <li><strong>{{ k }}</strong> {% for x in v %} {{ x.name }}{% endfor %}</li> + {% endfor %} </ul> </div> </div> + </div> + </div> <div class="row mt-2"> <p><a class="btn btn-primary btn-lg" href="#" role="button">Get help using ctrack »</a></p> |