From 2fa3b7134661deb201b1a9a9a907f0a8051640be Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 24 Oct 2020 16:05:57 +0100 Subject: Contact history for person page added but doesn't filter private events out yet --- .../templates/organisations/contact_history.html | 86 ++++++++++++++++++++++ .../templates/organisations/person_detail.html | 2 +- .../templates/organisations/person_list.html | 2 +- ctrack/organisations/tests/test_views.py | 21 ++++++ ctrack/organisations/urls.py | 4 +- ctrack/organisations/views.py | 19 ++++- 6 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 ctrack/organisations/templates/organisations/contact_history.html (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/templates/organisations/contact_history.html b/ctrack/organisations/templates/organisations/contact_history.html new file mode 100644 index 0000000..4768331 --- /dev/null +++ b/ctrack/organisations/templates/organisations/contact_history.html @@ -0,0 +1,86 @@ +{% extends "base.html" %} + +{% load static %} + +{% block title %}Contact History for {{ person }}{% endblock %} + +{% block content %} + + + + +
+
+
+

Contact history for {{ person }} | {{ person.organisation.name }}

+
+
+
+
+ {% if events %} + + + + + + + + + + + + + {% for event in events %} + + + + + + + + + {% endfor %} + +
DescriptionDateUserTypeCommentsAction
+ {{ event.type_descriptor }} + {% if event.private %} + PRIVATE + {% endif %} + {{ event.date|date:"d M Y G:H" }} + {% if event.user.name %} + {{ event.user.name }} + {% else %} + {{ event.user.username }} + {% endif %} + {{ event.short_description }} + {% if event.comments %} + {{ event.comments }} + {% else %} + NA + {% endif %} +
+ {% if event.document_link %} + [URL] + {% endif %} +
Edit +
+ {% else %} +

There is no contact history for {{ person }}.

+ {% endif %} +
+
+
+ +{% endblock %} diff --git a/ctrack/organisations/templates/organisations/person_detail.html b/ctrack/organisations/templates/organisations/person_detail.html index b51a891..407823b 100644 --- a/ctrack/organisations/templates/organisations/person_detail.html +++ b/ctrack/organisations/templates/organisations/person_detail.html @@ -16,9 +16,9 @@ {% elif person.voluntary_point_of_contact %} Voluntary Point of Contact {% else %} -   {% endif %} +

Contact History

diff --git a/ctrack/organisations/templates/organisations/person_list.html b/ctrack/organisations/templates/organisations/person_list.html index 80c7d6a..92cee0e 100644 --- a/ctrack/organisations/templates/organisations/person_list.html +++ b/ctrack/organisations/templates/organisations/person_list.html @@ -57,7 +57,7 @@ {{ p.organisation.name }} {{ p.mobile }} {{ p.email }} - Contact History + Contact History {% endfor %} diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py index c939894..c1eb3ef 100644 --- a/ctrack/organisations/tests/test_views.py +++ b/ctrack/organisations/tests/test_views.py @@ -16,6 +16,27 @@ from ..views import OrganisationListView pytestmark = pytest.mark.django_db +def test_person_history_view(user, client, org_with_people): + person = org_with_people.person_set.first() + e1 = SingleDateTimeEventFactory.create( + type_descriptor="MEETING", short_description="First Meeting" + ) + e2 = SingleDateTimeEventFactory.create( + type_descriptor="MEETING", short_description="Second Meeting" + ) + e1.participants.add(person) + e1.save() + e2.participants.add(person) + e2.save() + client.force_login(user) + response = client.get( + reverse("organisations:person_contact_history", kwargs={"person_id": person.pk}) + ) + assert response.status_code == 200 + html = response.content.decode("utf-8") + assert "First Meeting" in html + + 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) diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py index 6001ccd..5a7a580 100644 --- a/ctrack/organisations/urls.py +++ b/ctrack/organisations/urls.py @@ -7,8 +7,7 @@ from ctrack.organisations.views import ( OrganisationListView, PersonListView, essential_service_detail, - person_detail, OrganisationListViewByLeadInspector, oes_list, -) + person_detail, OrganisationListViewByLeadInspector, oes_list, person_contact_history, ) app_name = "organisations" @@ -21,6 +20,7 @@ urlpatterns = [ view=IncidentReportCreateView.as_view(), name="create_incident_report", ), + path("contact-history-for-person/", view=person_contact_history, name="person_contact_history"), path("", view=OrganisationListView.as_view(), name="list"), path("lead-inspector/", view=OrganisationListViewByLeadInspector.as_view(), name="list_by_inspector"), path("create", view=OrganisationCreate.as_view(), name="create"), diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index a1f43f7..52d226a 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -8,11 +8,10 @@ from django.db.models import Q from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, render from django.urls import reverse, reverse_lazy -from django.utils import timezone from django.views.generic import CreateView, DetailView, FormView, ListView from ctrack.caf.models import CAF, EssentialService -from ctrack.register.models import EngagementEvent, NoteEvent +from ctrack.register.models import EngagementEvent, NoteEvent, SingleDateTimeEvent from .forms import AddressInlineFormSet, IncidentReportForm, OrganisationCreateForm from .models import IncidentReport, Organisation, Person from .utils import filter_private_events @@ -29,6 +28,18 @@ def essential_service_detail(request, pk): return render(request, "organisations/essential_service_detail.html", context) +def person_contact_history(request, person_id): + events = SingleDateTimeEvent.objects.filter(participants__id=person_id).order_by( + "-date" + ) + person = get_object_or_404(Person, id=person_id) + return render( + request, + "organisations/contact_history.html", + {"events": events, "person": person}, + ) + + class OrganisationListViewByLeadInspector(ListView): model = Organisation template_name = "organisations/organisation_list.html" @@ -115,7 +126,9 @@ class OrganisationDetailView(PermissionRequiredMixin, DetailView): # simple datetime events for org # TODO - a note is not getting registered on org detail page after renamed datetime field so fix! - notes = NoteEvent.objects.filter(user=self.request.user, organisation=self.object).order_by("-created_date") + notes = NoteEvent.objects.filter( + user=self.request.user, organisation=self.object + ).order_by("-created_date") _sdes = [ filter_private_events( person.get_single_datetime_events(), self.request.user -- cgit v1.2.3