aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/caf/models.py4
-rw-r--r--ctrack/caf/templates/caf/caf_detail.html38
-rw-r--r--ctrack/organisations/views.py7
-rw-r--r--ctrack/register/models.py3
4 files changed, 48 insertions, 4 deletions
diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py
index d5ae98a..5e3e2e2 100644
--- a/ctrack/caf/models.py
+++ b/ctrack/caf/models.py
@@ -4,6 +4,8 @@ from ctrack.caf.managers import ApplicableSystemManager
from ctrack.organisations.models import Organisation, Person
from django.urls.base import reverse
+from ctrack.register.models import EngagementEvent
+
class Grading(models.Model):
GRADING_TYPE = [
@@ -158,6 +160,8 @@ class CAF(models.Model):
def get_assessments(self):
return self.cafassessment_set.all()
+ def get_events(self):
+ return EngagementEvent.objects.filter(related_caf=self).all().order_by("-date")
def __str__(self):
# Get the organisation and applicable system
diff --git a/ctrack/caf/templates/caf/caf_detail.html b/ctrack/caf/templates/caf/caf_detail.html
index c82b241..bfdff0c 100644
--- a/ctrack/caf/templates/caf/caf_detail.html
+++ b/ctrack/caf/templates/caf/caf_detail.html
@@ -63,7 +63,7 @@
<div class="card bg-light">
<div class="card-body">
<div class="card-title text-muted">NIS Systems <a
- href="{% url "caf:as_create_from_caf" object.pk %}" class="btn btn-primary btn-sm float-right">Add
+ href="{% url "caf:as_create_from_caf" object.pk %}" class="btn btn-outline-primary btn-sm float-right">Add
new...</a></div>
<div>
<table class="table table-responsive">
@@ -90,6 +90,42 @@
</div>
<div class="row">
+ <div class="col-md-12">
+ <div class="card bg-light">
+ <div class="card-body">
+ <div class="card-title text-muted">CAF History <a href="#" class="btn btn-outline-primary btn-sm float-right">Add new...</a></div>
+ <div class="table table-responsive">
+ <table class="table">
+ <thead>
+ <tr>
+ <th>Date</th>
+ <th>Event</th>
+ <th>Inspector</th>
+ <th>Comments</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for event in object.get_events %}
+ <tr>
+ <td>{{ event.date|date:"j F Y"}}</td>
+ <td>{{ event.type }}</td>
+ <td>{{ event.user }}</td>
+ <td>{{ event.comments }}</td>
+ </tr>
+ {% endfor %}
+
+ <tr>
+
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="row">
<div class="col-md-12 my-2">
<div class="card bg-light">
<div class="card-body">
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index 9658abf..c56c106 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -2,6 +2,7 @@ from typing import Any
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.db import transaction
+from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.urls import reverse, reverse_lazy
@@ -83,8 +84,12 @@ class OrganisationDetailView(LoginRequiredMixin, PermissionRequiredMixin, Detail
org = kwargs["object"]
peoples = org.person_set.all()
cafs = org.caf_set.all()
- engagement_events = EngagementEvent.objects.filter(participants__in=peoples).order_by("-date")
+
+ # Some events will not involve a participant, which is what ties an event to an organisation.
+ # Because we want to list events to an organisation here we must related it via the CAF object too...
+ engagement_events = EngagementEvent.objects.filter(Q(participants__in=peoples) | Q(related_caf__in=cafs)).order_by("-date")
essential_services = EssentialService.objects.filter(organisation=org)
+
no_addr = org.addresses.count()
if no_addr > 1:
context["no_addr"] = no_addr
diff --git a/ctrack/register/models.py b/ctrack/register/models.py
index f485761..a435002 100644
--- a/ctrack/register/models.py
+++ b/ctrack/register/models.py
@@ -4,7 +4,6 @@ from typing import Optional, Dict
from django.contrib.auth import get_user_model
from django.db import models
-from ctrack.caf.models import CAF
from ctrack.organisations.models import Person
@@ -64,7 +63,7 @@ class EngagementEvent(models.Model):
response_date_requested = models.DateField(blank=True, null=True)
response_received = models.DateField(blank=True, null=True)
related_caf = models.ForeignKey(
- CAF, blank=True, on_delete=models.CASCADE, null=True, help_text="If the event relates to a CAF, refer to it here."
+ "caf.CAF", blank=True, on_delete=models.CASCADE, null=True, help_text="If the event relates to a CAF, refer to it here."
)
comments = models.TextField(max_length=1000, blank=True, null=True, help_text="Use this to provide further detail about the event.")