From 420eb8308847e413d63b0692aba78cee7d1405f4 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 6 Mar 2020 17:52:48 +0000 Subject: reverted idea to use a custom manager to include NIS POC in systems list --- ctrack/caf/managers.py | 9 ++++++--- ctrack/caf/models.py | 5 ++++- ctrack/caf/templates/caf/applicablesystem_list.html | 6 +++++- ctrack/caf/views.py | 3 +-- 4 files changed, 16 insertions(+), 7 deletions(-) (limited to 'ctrack') diff --git a/ctrack/caf/managers.py b/ctrack/caf/managers.py index b3f2e63..cba8c83 100644 --- a/ctrack/caf/managers.py +++ b/ctrack/caf/managers.py @@ -1,17 +1,20 @@ +from django.db import connection from django.db import models -from django.db.models import QuerySet -from ctrack.organisations.models import Organisation, Person, Submode import ctrack.caf.models # to deal with circular import +from ctrack.organisations.models import Organisation, Person class ApplicableSystemManager(models.Manager): def with_primary_contact(self): """ + THIS IS NOT CURRENTLY USED BUT LEAVING IT IN FOR REF + BETTER WAS TO ADD A MODEL METHOD TO FIND THE POC FOR EACH + ORGANISATION AND ADAPT THE TEMPLATE TO USE THAT. + Add in the name of the primary nis contact to the context. Using Custom Managers Django docs for an example. """ - from django.db import connection with connection.cursor() as cursor: cursor.execute(""" SELECT a.id, a.name, o.id, c.id, sm.id, p.id, o.name diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py index a031657..bec59d6 100644 --- a/ctrack/caf/models.py +++ b/ctrack/caf/models.py @@ -56,11 +56,14 @@ class ApplicableSystem(models.Model): class Meta: verbose_name = "Applicable System" - objects = ApplicableSystemManager() + def get_primary_contact(self): + return self.organisation.person_set.filter(primary_nis_contact=True) def __str__(self): return f"{self.organisation.name} | {self.name}" + objects = ApplicableSystemManager() + class CAF(models.Model): quality_grading = models.ForeignKey(Grading, on_delete=models.CASCADE, blank=True, null=True, diff --git a/ctrack/caf/templates/caf/applicablesystem_list.html b/ctrack/caf/templates/caf/applicablesystem_list.html index 059b61e..f8d6195 100644 --- a/ctrack/caf/templates/caf/applicablesystem_list.html +++ b/ctrack/caf/templates/caf/applicablesystem_list.html @@ -31,7 +31,11 @@ {{ sys.caf.confidence_grading.descriptor }} {{ sys.caf.triage_review_date }} {{ sys.caf.triage_review_inspector.name }} - {{ sys.nis_contact }} + {% if sys.get_primary_contact %} + {{ sys.get_primary_contact.first }} + {% else %} + NA + {% endif %} {% endfor %} diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index fceb869..5ded2dc 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -25,8 +25,7 @@ class ListApplicableSystem(ListView): template_name = "caf/applicablesystem_list.html" def get_queryset(self): - # TODO sort this list using basic Python sorted() - ess = ApplicableSystem.objects.with_primary_contact() # returns a list, not a QuerySet + ess = ApplicableSystem.objects.all().order_by("organisation__name") return ess def get_context_data(self, **kwargs): -- cgit v1.2.3