aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-21 16:09:05 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-21 16:09:05 +0100
commitcbddf7c7fad44f62b1cf057158bcf9e53f8e1bb4 (patch)
treeed3eb1783d7a0a73561a081e23cb5839ecb0bffb
parentcadbccdf61525c67107ab0f1b1206f4d5e07861a (diff)
now have an OES-only organisation page
-rw-r--r--ctrack/core/views.py2
-rw-r--r--ctrack/organisations/templates/organisations/organisation_list.html29
-rw-r--r--ctrack/organisations/tests/test_views.py26
-rw-r--r--ctrack/organisations/urls.py3
-rw-r--r--ctrack/organisations/views.py14
-rw-r--r--ctrack/templates/pages/home.html9
6 files changed, 68 insertions, 15 deletions
diff --git a/ctrack/core/views.py b/ctrack/core/views.py
index 5268f66..d9129e8 100644
--- a/ctrack/core/views.py
+++ b/ctrack/core/views.py
@@ -31,12 +31,14 @@ def home_page(request):
no_orgs = Organisation.objects.count()
no_people = Person.objects.count()
no_cafs = CAF.objects.count()
+ no_oes = Organisation.objects.filter(oes=True).count()
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_oes": no_oes,
"no_orgs": no_orgs,
"no_people": no_people,
"no_cafs": no_cafs,
diff --git a/ctrack/organisations/templates/organisations/organisation_list.html b/ctrack/organisations/templates/organisations/organisation_list.html
index 8e7b72a..dfce156 100644
--- a/ctrack/organisations/templates/organisations/organisation_list.html
+++ b/ctrack/organisations/templates/organisations/organisation_list.html
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% load static %}
-{% block title %} Organisations{% endblock %}
+{% block title %}Organisations/OES{% endblock %}
{% block content %}
@@ -25,14 +25,17 @@
<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>
- {% if inspector %}
- Organisations (Lead inspector: {{ inspector.name }})
+ {% if inspector and is_oes %}
+ OES (Lead inspector: {{ inspector.name }})
+ {% elif is_oes %}
+ OES
{% 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
+ <p>Use the search box to filter the table. The table can be exported in various formats using the buttons below.
+ These
downloads will respect the filtering used.</p>
<div class="row justify-content-center">
<div class="col-md-12 my-2 py-2">
@@ -44,17 +47,20 @@
<th>Lead Inspector</th>
<th>Deputy Lead Inspector</th>
<th>Point of Contact</th>
+ <th>OES</th>
</tr>
</thead>
{% for org in organisation_list %}
<tr>
<td><a href="{% url "organisations:detail" org.slug %}">{{ org.name }}</a></td>
<td>{{ org.submode }}</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 %}
+ {% 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 %}
@@ -67,6 +73,11 @@
No contact listed
{% endif %}
</td>
+ {% if org.oes is True %}
+ <td>Yes</td>
+ {% else %}
+ <td>No</td>
+ {% endif %}
</tr>
{% endfor %}
</table>
diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py
index e1b31fb..c939894 100644
--- a/ctrack/organisations/tests/test_views.py
+++ b/ctrack/organisations/tests/test_views.py
@@ -9,7 +9,7 @@ from ctrack.organisations.tests.factories import (
OrganisationFactory,
SingleDateTimeEventFactory,
)
-from ctrack.organisations.views import IncidentReportCreateView, OrganisationDetailView
+from ctrack.organisations.views import IncidentReportCreateView, OrganisationDetailView, oes_list
from ..utils import filter_private_events
from ..views import OrganisationListView
@@ -49,7 +49,6 @@ def test_meetings_in_organisation_detail_view(user, client, org_with_people):
assert "First Meeting" in html
-
def test_private_event_filter(user, org_with_people):
"""
In this test we are creating five events, using two different users.
@@ -206,6 +205,29 @@ def test_organisation_list_view():
assert len(response.context_data["organisation_list"]) == 3
+def test_oes_list_view():
+ OrganisationFactory.create(oes=True)
+ OrganisationFactory.create(oes=True)
+ OrganisationFactory.create(oes=True)
+
+ factory = RequestFactory()
+ user = get_user_model().objects.create_user(
+ username="testy", email="testy@test.com", password="test1020"
+ )
+ # This user needs permission to acccess the list view
+ org_list_permission = Permission.objects.get(name="Can view organisation")
+ assert user.user_permissions.count() == 0
+ user.user_permissions.add(org_list_permission)
+ assert user.has_perm("organisations.view_organisation")
+ user.save()
+ request = factory.get("/organisations/oes")
+ request.user = user
+ response = oes_list(request)
+ assert response.status_code == 200
+ html = response.content.decode("utf-8")
+ assert "OES" in html
+
+
def test_only_member_of_cct_user_group_can_view_org_list():
OrganisationFactory.create()
OrganisationFactory.create()
diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py
index 33a741c..6001ccd 100644
--- a/ctrack/organisations/urls.py
+++ b/ctrack/organisations/urls.py
@@ -7,12 +7,13 @@ from ctrack.organisations.views import (
OrganisationListView,
PersonListView,
essential_service_detail,
- person_detail, OrganisationListViewByLeadInspector,
+ person_detail, OrganisationListViewByLeadInspector, oes_list,
)
app_name = "organisations"
urlpatterns = [
+ path("oes/", oes_list, name="list_oes"),
path("people/", view=PersonListView.as_view(), name="people"),
path("<slug:slug>/", view=OrganisationDetailView.as_view(), name="detail"),
path(
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index 1d1978e..5726aa2 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -36,8 +36,11 @@ class OrganisationListViewByLeadInspector(ListView):
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["organisation_list"] = Organisation.objects.filter(
+ lead_inspector=inspector, oes=True
+ )
context["inspector"] = inspector
+ context["is_oes"] = True
return context
@@ -52,6 +55,15 @@ def person_detail(request, person_id):
return render(request, "organisations/person_detail.html", {"person": p})
+def oes_list(request):
+ oes = Organisation.objects.filter(oes=True)
+ return render(
+ request,
+ "organisations/organisation_list.html",
+ {"organisation_list": oes, "is_oes": True},
+ )
+
+
class OrganisationCreate(PermissionRequiredMixin, CreateView):
model = Organisation
template_name = "organisations/org_create_formset.html"
diff --git a/ctrack/templates/pages/home.html b/ctrack/templates/pages/home.html
index 7c414b8..e1314ac 100644
--- a/ctrack/templates/pages/home.html
+++ b/ctrack/templates/pages/home.html
@@ -29,7 +29,8 @@
OES/Organisations
</h3>
<p>There are currently <span class="lead font-weight-bold">{{ no_orgs }}</span> <a
- href="{% url "organisations:list" %}">organisations</a> on ctrack, comprising <span
+ href="{% url "organisations:list" %}">organisations</a> on ctrack, of which <span
+ class="lead font-weight-bold">{{ no_oes }}</span> are OES, comprising <span
class="lead font-weight-bold">{{ no_people }}</span> <a href="{% url "organisations:people" %}">people</a>.
OES are responsible for <span class="lead font-weight-bold">{{ no_essential_services }}</span> NIS <a
href="#">essential services</a>. There have been a total of <span
@@ -47,6 +48,9 @@
href="{% url "organisations:list" %}">All
organisations</a><span class="badge badge-secondary">{{ no_orgs }}</span></li>
<li class="list-group-item list-group-item-dark d-flex justify-content-between align-items-center"><a
+ href="{% url "organisations:list_oes" %}">All
+ OES</a><span class="badge badge-secondary">{{ no_oes }}</span></li>
+ <li class="list-group-item list-group-item-dark d-flex justify-content-between align-items-center"><a
href="{% url "organisations:people" %}">All
people</a><span class="badge badge-secondary">{{ no_people }}</span></li>
<li class="list-group-item list-group-item-dark d-flex justify-content-between align-items-center"><a
@@ -105,7 +109,8 @@
<h5>Lead Inspectors</h5>
<ul class="list-unstyled">
{% for k, v in submode_inspector_dict.items %}
- <li><strong>{{ k }}</strong> &nbsp; {% for x in v %} <a href="{% url "organisations:list_by_inspector" x.id %}">{{ x.name }}</a> -{% endfor %}</li>
+ <li><strong>{{ k }}</strong> &nbsp; {% for x in v %}
+ <a href="{% url "organisations:list_by_inspector" x.id %}">{{ x.name }}</a> -{% endfor %}</li>
{% endfor %}
</ul>
</div>