From 80a7c8e991c7127bcf5c77b8a47d75d95ea8ce34 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 2 Oct 2020 20:19:41 +0100 Subject: overly-complex template code for handling CAF events in CAF detail form --- ctrack/caf/templates/caf/caf_detail.html | 37 +++++++++++++++++++++----------- ctrack/caf/views.py | 22 +++++++++++++++---- 2 files changed, 42 insertions(+), 17 deletions(-) (limited to 'ctrack/caf') diff --git a/ctrack/caf/templates/caf/caf_detail.html b/ctrack/caf/templates/caf/caf_detail.html index 2e88b15..500ae62 100644 --- a/ctrack/caf/templates/caf/caf_detail.html +++ b/ctrack/caf/templates/caf/caf_detail.html @@ -16,25 +16,36 @@
-

Current status:

-
-
- {% if not events %} +

History:

+ {% if tde and sde %} +
+
No events registered for this CAF. - Register Event - {% endif %} + Register Event +
-
+ {% endif %}
-
+
    - {% for event in events %} - {% if not event.ended %} -
  • {{ event.event.type }} - Started: {{ event.event.date|date:"j M Y" }}
  • + {% for event in twin_date_events %} + {% if event.end_date %} +
  • {{ event.type }} + Completed: {{ event.end_date|date:"j M Y" }}
  • + {% else %} +
  • {{ event.type }} + Started: {{ event.date|date:"j M Y" }}
  • {% endif %} {% endfor %} + {% for event in single_date_events %} +
  • + {{ event.type }} + Completed: {{ event.date|date:"j M Y" }}
  • + + {% endfor %} +
diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index d11fa8c..14a2edb 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -32,17 +32,31 @@ def caf_detail_view(request, pk): lst_scores = [ass, CAFAssessmentOutcomeScore.objects.filter(caf_assessment=ass)] _scrs.append(lst_scores) events_related_to_caf = caf.get_events() - events = [] + single_date_events = [] + twin_date_events = [] for event in events_related_to_caf: - if not event.end_date: - events.append(dict(event=event, ended=False, badge_code="warning")) + if event.type.single_date_type: + single_date_events.append(event) + else: + twin_date_events.append(event) + if single_date_events: + sde = True + else: + sde = False + if twin_date_events: + tde = True + else: + tde = False context = { "object": caf, "assessments_and_scores": _scrs, "organisation": caf.organisation, "systems": caf.systems.all(), - "events": events + "single_date_events": single_date_events, + "sde": sde, + "tde": tde, + "twin_date_events": twin_date_events } return render(request, "caf/caf_detail.html", context) -- cgit v1.2.3