diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-03-06 17:52:48 +0000 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-03-06 17:52:48 +0000 |
commit | 420eb8308847e413d63b0692aba78cee7d1405f4 (patch) | |
tree | 9c0d78c01ac94abdc7db269a65d5314e98133a25 /ctrack | |
parent | d901a8af93efa94545b5bd6ab7a323786923cb67 (diff) |
reverted idea to use a custom manager to include NIS POC in systems list
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/managers.py | 9 | ||||
-rw-r--r-- | ctrack/caf/models.py | 5 | ||||
-rw-r--r-- | ctrack/caf/templates/caf/applicablesystem_list.html | 6 | ||||
-rw-r--r-- | ctrack/caf/views.py | 3 |
4 files changed, 16 insertions, 7 deletions
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 @@ <td class="tabaligncenter">{{ sys.caf.confidence_grading.descriptor }}</td> <td>{{ sys.caf.triage_review_date }}</td> <td>{{ sys.caf.triage_review_inspector.name }}</td> - <td>{{ sys.nis_contact }}</td> + {% if sys.get_primary_contact %} + <td>{{ sys.get_primary_contact.first }}</td> + {% else %} + <td>NA</td> + {% endif %} </tr> {% endfor %} </table> 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): |