From 5ee4335eb92f2dc35b31c208bce8d8e8aef9e5f2 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 20 Oct 2020 16:39:48 +0100 Subject: added org list hard-filtered by lead inspector --- ctrack/organisations/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ctrack/organisations/views.py') diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index ae98305..1d1978e 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -1,6 +1,7 @@ import itertools from typing import Any +from django.contrib.auth import get_user_model from django.contrib.auth.mixins import PermissionRequiredMixin from django.db import transaction from django.db.models import Q @@ -28,6 +29,18 @@ def essential_service_detail(request, pk): return render(request, "organisations/essential_service_detail.html", context) +class OrganisationListViewByLeadInspector(ListView): + model = Organisation + template_name = "organisations/organisation_list.html" + + def get_context_data(self, *, object_list=None, **kwargs): + context = super().get_context_data(**kwargs) + inspector = get_user_model().objects.get(id=self.kwargs.get("id")) + context["organisation_list"] = Organisation.objects.filter(lead_inspector=inspector) + context["inspector"] = inspector + return context + + class PersonListView(PermissionRequiredMixin, ListView): model = Person template_name = "organisations/person_list.html" -- cgit v1.2.3