aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/register/models.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-09-29 12:02:36 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-09-29 12:02:36 +0100
commitcf4ee94db89e697d625106e78831b7e219cd8c03 (patch)
treec1441f4d521c43f19664e5c50616df7a5564fa66 /ctrack/register/models.py
parent5f477692e5b3a1c2209c0c17e5dc303ea81e7a32 (diff)
OES engagements on org detail page improved with dates
Diffstat (limited to 'ctrack/register/models.py')
-rw-r--r--ctrack/register/models.py27
1 files changed, 27 insertions, 0 deletions
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}"
+
+