diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-24 16:05:57 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-24 16:05:57 +0100 |
commit | 2fa3b7134661deb201b1a9a9a907f0a8051640be (patch) | |
tree | 5236b0fde2b8dba57f49dba098df0edec9980741 | |
parent | 457cd45a13a4cd73626d70367be1179a070700f3 (diff) |
Contact history for person page added but doesn't filter private events out yet
-rw-r--r-- | ctrack/organisations/templates/organisations/contact_history.html | 86 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/person_detail.html | 2 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/person_list.html | 2 | ||||
-rw-r--r-- | ctrack/organisations/tests/test_views.py | 21 | ||||
-rw-r--r-- | ctrack/organisations/urls.py | 4 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 19 |
6 files changed, 127 insertions, 7 deletions
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 %} + + <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> + <script type="application/javascript"> + $(document).ready(function () { + $('#datatable').DataTable({ + ordering: true, + searching: true, + buttons: true, + dom: 'B<"clear">lfrtip', + paging: false, + }); + }); + </script> + + <div class="col-12 m-2"> + <div class="row"> + <div class="col-12 mb-2"> + <h3>Contact history for {{ person }} | <span class="text-muted">{{ person.organisation.name }}</span></h3> + </div> + </div> + <div class="row justify-content-center"> + <div class="col-md-12"> + {% if events %} + <table id="datatable" class="table table-striped table-bordered"> + <thead> + <tr> + <th>Description</th> + <th>Date</th> + <th>User</th> + <th>Type</th> + <th>Comments</th> + <th>Action</th> + </tr> + </thead> + <tbody> + {% for event in events %} + <tr> + <td> + {{ event.type_descriptor }} + {% if event.private %} + <span class="badge badge-warning float-right">PRIVATE</span> + {% endif %} + </td> + <td>{{ event.date|date:"d M Y G:H" }}</td> + <td> + {% if event.user.name %} + {{ event.user.name }} + {% else %} + {{ event.user.username }} + {% endif %} + </td> + <td>{{ event.short_description }}</td> + <td> + {% if event.comments %} + {{ event.comments }} + {% else %} + NA + {% endif %} + <br> + {% if event.document_link %} + <a class="small" href="{{ event.document_link }}">[URL]</a> + {% endif %} + </td> + <td><a + href="{% url "register:event_update_simple_event_from_org" event.pk person.organisation.slug %}" + class="btn btn-outline-secondary btn-sm" role="button">Edit</a> + </td> + </tr> + {% endfor %} + </tbody> + </table> + {% else %} + <p>There is no contact history for {{ person }}.</p> + {% endif %} + </div> + </div> + </div> + +{% 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 %} <span class="badge badge-dark">Voluntary Point of Contact</span> {% else %} - {% endif %} </h3> + <p><a href="{% url "organisations:person_contact_history" person.pk %}">Contact History</a></p> </div> </div> <div class="row"> 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 @@ <td><a href="{% url "organisations:detail" p.organisation.slug %}">{{ p.organisation.name }}</a></td> <td>{{ p.mobile }}</td> <td><a href="mailto:{{ p.email }}">{{ p.email }}</a></td> - <td><a href="#">Contact History</a></td> + <td><a href="{% url "organisations:person_contact_history" p.pk %} ">Contact History</a></td> </tr> {% endfor %} </table> 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/<int:person_id>", view=person_contact_history, name="person_contact_history"), 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"), 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 |