diff options
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_list.html | 14 | ||||
-rw-r--r-- | ctrack/organisations/tests/test_views.py | 7 | ||||
-rw-r--r-- | ctrack/organisations/urls.py | 5 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 13 | ||||
-rw-r--r-- | ctrack/templates/pages/home.html | 2 |
5 files changed, 36 insertions, 5 deletions
diff --git a/ctrack/organisations/templates/organisations/organisation_list.html b/ctrack/organisations/templates/organisations/organisation_list.html index a45cae8..8e7b72a 100644 --- a/ctrack/organisations/templates/organisations/organisation_list.html +++ b/ctrack/organisations/templates/organisations/organisation_list.html @@ -25,7 +25,11 @@ <path fill-rule="evenodd" d="M7 14s-1 0-1-1 1-4 5-4 5 3 5 4-1 1-1 1H7zm4-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-5.784 6A2.238 2.238 0 0 1 5 13c0-1.355.68-2.75 1.936-3.72A6.325 6.325 0 0 0 5 9c-4 0-5 3-5 4s1 1 1 1h4.216zM4.5 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z"/> </svg> - Organisations + {% if inspector %} + Organisations (Lead inspector: {{ inspector.name }}) + {% else %} + Organisations + {% endif %} </h3> <span><a href="{% url "organisations:create" %}">[Create new...]</a></span></h3> <p>Use the search box to filter the table. The table can be exported in various formats using the buttons below. These @@ -38,6 +42,7 @@ <th>Organisation</th> <th>Sub-mode</th> <th>Lead Inspector</th> + <th>Deputy Lead Inspector</th> <th>Point of Contact</th> </tr> </thead> @@ -45,7 +50,12 @@ <tr> <td><a href="{% url "organisations:detail" org.slug %}">{{ org.name }}</a></td> <td>{{ org.submode }}</td> - <td>{{ org.lead_inspector.name }}</td> + {% if org.lead_inspector %} + <td><a href="{% url "organisations:list_by_inspector" org.lead_inspector.pk %}">{{ org.lead_inspector.name }}</a></td> + {% else %} + <td>{{ org.lead_inspector.name }}</td> + {% endif %} + <td>{{ org.deputy_lead_inspector.name }}</td> <td> {% if org.primary_contacts %} <ul style="list-style-type:none; float:left; padding: 0"> diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py index a567fab..3584d96 100644 --- a/ctrack/organisations/tests/test_views.py +++ b/ctrack/organisations/tests/test_views.py @@ -16,6 +16,13 @@ from ..views import OrganisationListView pytestmark = pytest.mark.django_db +def test_organisation_by_inspector_view(inspector1, inspector2, client, submode): + org = OrganisationFactory(submode=submode, lead_inspector=inspector1, deputy_lead_inspector=inspector2) + client.force_login(inspector1) + response = client.get(reverse("organisations:list_by_inspector", args=[inspector1.id])) + assert response.status_code == 200 + + def test_meetings_in_organisation_detail_view(user, client, org_with_people): org_list_permission = Permission.objects.get(name="Can view organisation") assert user.user_permissions.count() == 0 diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py index b5dadee..33a741c 100644 --- a/ctrack/organisations/urls.py +++ b/ctrack/organisations/urls.py @@ -7,7 +7,7 @@ from ctrack.organisations.views import ( OrganisationListView, PersonListView, essential_service_detail, - person_detail, + person_detail, OrganisationListViewByLeadInspector, ) app_name = "organisations" @@ -21,12 +21,13 @@ urlpatterns = [ name="create_incident_report", ), path("", view=OrganisationListView.as_view(), name="list"), + path("lead-inspector/<int:id>", view=OrganisationListViewByLeadInspector.as_view(), name="list_by_inspector"), path("create", view=OrganisationCreate.as_view(), name="create"), path( "essentialservice/<int:pk>", essential_service_detail, name="essential_service_detail", ), - path("person/<int:person_id>", person_detail, name="person-detail"), + path("person/<int:person_id>", person_detail, name="person-detail"), # path("create", view=OrganisationCreate.as_view(), name="create") ] 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" diff --git a/ctrack/templates/pages/home.html b/ctrack/templates/pages/home.html index 6436bed..7c414b8 100644 --- a/ctrack/templates/pages/home.html +++ b/ctrack/templates/pages/home.html @@ -105,7 +105,7 @@ <h5>Lead Inspectors</h5> <ul class="list-unstyled"> {% for k, v in submode_inspector_dict.items %} - <li><strong>{{ k }}</strong> {% for x in v %} <a href="#">{{ x.name }}</a> -{% endfor %}</li> + <li><strong>{{ k }}</strong> {% for x in v %} <a href="{% url "organisations:list_by_inspector" x.id %}">{{ x.name }}</a> -{% endfor %}</li> {% endfor %} </ul> </div> |