aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/templates/organisations/organisation_detail.html43
-rw-r--r--ctrack/organisations/views.py2
-rw-r--r--ctrack/register/models.py27
3 files changed, 62 insertions, 10 deletions
diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html
index c02f0ee..4af5d6f 100644
--- a/ctrack/organisations/templates/organisations/organisation_detail.html
+++ b/ctrack/organisations/templates/organisations/organisation_detail.html
@@ -19,7 +19,7 @@
</div>
</div>
- <div class="row" id="top-row">
+ <div class="row" id="top-row">
<div class="col-md-6">
<div class="card bg-light">
@@ -91,7 +91,7 @@
</table>
</div>
</div>
- </div>
+ </div>
</div>
<div class="row pb-2">
@@ -130,7 +130,6 @@
</div>
-
<div class="row">
<div class="col-md-12 my-2">
<div class="card bg-light">
@@ -205,12 +204,38 @@
class="btn btn-outline-primary btn-sm float-right">Add
new...</a></div>
<div class="table table-responsive">
- <table class="table table-bordered">
- {% if engagement_events|length > 0 %}{% for event in engagement_events %}
- <tr>
- <td><a href="#">{{ event.type }}</a></td>
- <td>{{ event.short_description }}</td>
- </tr> {% endfor %}
+ <table class="table table-sm table-bordered">
+ <thead>
+ <tr>
+ <th>Date</th>
+ <th>Type</th>
+ <th>Description</th>
+ <th>Response Requested</th>
+ <th>Response Due</th>
+ </tr>
+ </thead>
+ {% if engagement_events|length > 0 %}
+ {% for event in engagement_events %}
+ <tr>
+ <td>{{ event.date |date:"D d M Y H:i" }}</td>
+ <td><a href="#">{{ event.type }}</a></td>
+ <td>{{ event.short_description }}</td>
+ {% if event.response_date_requested %}
+ <td style="color: {{ event.days_to_response_due.descriptor }}">{{ event.response_date_requested |date:"D d M Y" }}</td>
+ {% else %}
+ <td>NA</td>
+ {% endif %}
+ {% if event.response_received %}
+ <td>{{ event.response_received | date:"D d M Y" }}</td>
+ {% else %}
+ {% if event.response_date_requested %}
+ <td style="color: {{ event.days_to_response_due.descriptor }};">{{ event.days_to_response_due.days}} {{ event.days_to_response_due.day_str }}</td>
+ {% else %}
+ <td>NA</td>
+ {% endif %}
+ {% endif %}
+ </tr>
+ {% endfor %}
{% else %}
<a class="btn btn-outline-primary btn-sm" href="{% url "register:create" %}" role="button">Add
new...</a>
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index de6d819..9658abf 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -83,7 +83,7 @@ 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)
+ engagement_events = EngagementEvent.objects.filter(participants__in=peoples).order_by("-date")
essential_services = EssentialService.objects.filter(organisation=org)
no_addr = org.addresses.count()
if no_addr > 1:
diff --git a/ctrack/register/models.py b/ctrack/register/models.py
index ef19ca6..8a01875 100644
--- a/ctrack/register/models.py
+++ b/ctrack/register/models.py
@@ -1,9 +1,26 @@
+from datetime import date as std_date
+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
+def _style_descriptor(days: int) -> str:
+ if days < 1:
+ return "red"
+ elif 0 < days < 5:
+ return "orange"
+ else:
+ return "black"
+
+
+def _day_string(days: int) -> str:
+ if days < 1 or days > 1:
+ return "days"
+ else:
+ return "day"
class EngagementType(models.Model):
"""
@@ -49,7 +66,17 @@ class EngagementEvent(models.Model):
)
comments = models.TextField(max_length=1000, blank=True, null=True)
+ def days_to_response_due(self) -> Optional[Dict[int, str]]:
+ if self.response_date_requested:
+ today = std_date.today()
+ diff = self.response_date_requested - today
+ return dict(days=diff.days, descriptor=_style_descriptor(diff.days), day_str=_day_string(diff.days))
+ else:
+ return None
+
def __str__(self):
d = self.date.date()
iso_format_date = d.isoformat()
return f"{iso_format_date} | {self.type.descriptor} | {self.short_description}"
+
+