aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/caf/managers.py12
-rw-r--r--ctrack/caf/models.py7
-rw-r--r--ctrack/organisations/tests/test_models.py6
3 files changed, 20 insertions, 5 deletions
diff --git a/ctrack/caf/managers.py b/ctrack/caf/managers.py
index cba8c83..4d8c134 100644
--- a/ctrack/caf/managers.py
+++ b/ctrack/caf/managers.py
@@ -1,8 +1,8 @@
from django.db import connection
from django.db import models
-import ctrack.caf.models # to deal with circular import
-from ctrack.organisations.models import Organisation, Person
+import ctrack.caf.models as caf_models # to deal with circular import
+import ctrack.organisations.models as org_models
class ApplicableSystemManager(models.Manager):
@@ -16,14 +16,16 @@ class ApplicableSystemManager(models.Manager):
Using Custom Managers Django docs for an example.
"""
with connection.cursor() as cursor:
- cursor.execute("""
+ cursor.execute(
+ """
SELECT a.id, a.name, o.id, c.id, sm.id, p.id, o.name
FROM caf_applicablesystem a, organisations_organisation o, organisations_person p, caf_caf c, organisations_submode sm
WHERE a.organisation_id = o.id AND a.caf_id = c.id AND p.organisation_id = o.id AND o.submode_id = sm.id AND p.primary_nis_contact = True;
- """)
+ """
+ )
result_list = []
for row in cursor.fetchall():
- org = Organisation.objects.get(pk=row[2])
+ org = org_models.Organisation.objects.get(pk=row[3])
caf = ctrack.caf.models.CAF.objects.get(pk=row[3])
ass = self.model(id=row[0], name=row[1], organisation=org, caf=caf)
ass.nis_contact = Person.objects.get(pk=row[5])
diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py
index 27220bc..a4afc29 100644
--- a/ctrack/caf/models.py
+++ b/ctrack/caf/models.py
@@ -158,3 +158,10 @@ class CAF(models.Model):
# Get the organisation and applicable system
ass = ApplicableSystem.objects.filter(caf=self).first()
return f"CAF | {ass.organisation.name}_v{self.version}"
+
+
+class EssentialService(models.Model):
+ name = models.CharField(max_length=256)
+ description = models.CharField(max_length=512)
+ organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE)
+ systems = models.ManyToManyField(ApplicableSystem)
diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py
index c6314af..8287e97 100644
--- a/ctrack/organisations/tests/test_models.py
+++ b/ctrack/organisations/tests/test_models.py
@@ -2,6 +2,7 @@ import pytest
from slugify import slugify
from ctrack.organisations.models import IncidentReport, Organisation
+from ctrack.caf.models import EssentialService
pytestmark = pytest.mark.django_db
@@ -21,3 +22,8 @@ def test_update_organisation(org_with_people):
def test_new_address(addr):
# The address "has" an organisation
assert addr.organisation.name
+
+
+def test_essential_service():
+ es = EssentialService()
+ assert es