diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-02 20:19:41 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-02 20:19:41 +0100 |
commit | 80a7c8e991c7127bcf5c77b8a47d75d95ea8ce34 (patch) | |
tree | 9db9643e73ff01ed5ad28ea6c6b9eb2f42c1be0d | |
parent | 6820cee6193b33023cce516af77302446ee42021 (diff) |
overly-complex template code for handling CAF events in CAF detail form
-rw-r--r-- | ctrack/caf/templates/caf/caf_detail.html | 37 | ||||
-rw-r--r-- | ctrack/caf/views.py | 22 | ||||
-rw-r--r-- | ctrack/core/utils.py | 2 | ||||
-rw-r--r-- | ctrack/register/admin.py | 2 | ||||
-rw-r--r-- | ctrack/register/migrations/0006_engagementtype_single_date_type.py | 18 | ||||
-rw-r--r-- | ctrack/register/models.py | 1 | ||||
-rw-r--r-- | ctrack/register/tests/factories.py | 1 |
7 files changed, 64 insertions, 19 deletions
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 @@ <div class="row"> <div class="col-12"> - <h3>Current status:</h3> - <div class="row"> - <div class="col-md-12 m-2 p-1"> - {% if not events %} + <h3>History:</h3> + {% if tde and sde %} + <div class="row"> + <div class="col-md-12"> No events registered for this CAF. - <span class="float-right"><a href="#" type="button" class="btn btn-outline-primary btn-sm">Register Event</a></span> - {% endif %} + <span class="float-right pb-1"><a href="#" type="button" class="btn btn-outline-primary btn-sm">Register Event</a></span> + </div> </div> - </div> + {% endif %} <div class="row"> - <div class="col-md-12"> + <div class="col-md-12 my-1"> <ul class="list-group"> - {% for event in events %} - {% if not event.ended %} - <li class="list-group-item list-group-item-{{ event.badge_code }}"><a - href="#">{{ event.event.type }}</a> - <span class="float-right">Started: {{ event.event.date|date:"j M Y" }}</span></li> + {% for event in twin_date_events %} + {% if event.end_date %} + <li class="list-group-item list-group-item-success"><a + href="#">{{ event.type }}</a> + <span class="float-right">Completed: {{ event.end_date|date:"j M Y" }}</span></li> + {% else %} + <li class="list-group-item list-group-item-warning"><a + href="#">{{ event.type }}</a> + <span class="float-right">Started: {{ event.date|date:"j M Y" }}</span></li> {% endif %} {% endfor %} + {% for event in single_date_events %} + <li class="list-group-item list-group-item-{{ event.badge_code }}"> + <a href="#">{{ event.type }}</a> + <span class="float-right">Completed: {{ event.date|date:"j M Y" }}</span></li> + </li> + {% endfor %} + </ul> </div> </div> </ul> 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) diff --git a/ctrack/core/utils.py b/ctrack/core/utils.py index eed8e0b..baec100 100644 --- a/ctrack/core/utils.py +++ b/ctrack/core/utils.py @@ -213,7 +213,7 @@ def populate_db(**kwargs): EngagementTypeFactory.create(descriptor="Email", enforcement_instrument=False) EngagementTypeFactory.create(descriptor="CAF - Initial Review", enforcement_instrument=False) EngagementTypeFactory.create(descriptor="CAF - Peer Review") - EngagementTypeFactory.create(descriptor="CAF - Validation") + EngagementTypeFactory.create(descriptor="CAF - Validation", single_date_type=False) EngagementTypeFactory.create(descriptor="CAF - Sent to Rosa") EngagementTypeFactory.create(descriptor="CAF - Received from OES (USB)") EngagementTypeFactory.create(descriptor="Audit - Onsite") diff --git a/ctrack/register/admin.py b/ctrack/register/admin.py index 8b4930e..09cd6da 100644 --- a/ctrack/register/admin.py +++ b/ctrack/register/admin.py @@ -11,7 +11,7 @@ class EngagementEventAdmin(admin.ModelAdmin): class EngagementEventTypeAdmin(admin.ModelAdmin): model = EngagementEventAdmin - list_display = ("descriptor", "enforcement_instrument", "regulation_reference") + list_display = ("descriptor", "enforcement_instrument", "single_date_type", "regulation_reference") admin.site.register(EngagementEvent, EngagementEventAdmin) diff --git a/ctrack/register/migrations/0006_engagementtype_single_date_type.py b/ctrack/register/migrations/0006_engagementtype_single_date_type.py new file mode 100644 index 0000000..fdc0d1f --- /dev/null +++ b/ctrack/register/migrations/0006_engagementtype_single_date_type.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.12 on 2020-10-02 18:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('register', '0005_auto_20201002_1536'), + ] + + operations = [ + migrations.AddField( + model_name='engagementtype', + name='single_date_type', + field=models.BooleanField(default=False), + ), + ] diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 8c35ef9..6cfe8d8 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -33,6 +33,7 @@ class EngagementType(models.Model): enforcement_instrument = models.BooleanField(default=False) regulation_reference = models.CharField(max_length=100, blank=True, null=True) comments = models.TextField(max_length=1000, blank=True, null=True) + single_date_type = models.BooleanField(default=False, blank=False) def __str__(self): return self.descriptor diff --git a/ctrack/register/tests/factories.py b/ctrack/register/tests/factories.py index 4334f3d..b3666dd 100644 --- a/ctrack/register/tests/factories.py +++ b/ctrack/register/tests/factories.py @@ -43,6 +43,7 @@ class EngagementTypeFactory(factory.django.DjangoModelFactory): descriptor = "Generic Engagement Type" enforcement_instrument = True regulation_reference = factory.LazyFunction(_regulation_scrambler) + single_date_type = True class EngagementEventFactory(factory.django.DjangoModelFactory): |