aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/caf
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-08-27 11:03:14 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-08-27 11:03:14 +0100
commitef287a9397cd911d55a37eb98934c203a59a8154 (patch)
tree1744debb6f44b6cd2623ec028c2035497a73946a /ctrack/caf
parent36759e44bc59747256332809097342a32ab6db19 (diff)
massive - removed migrations and reform db schema - NOT COMPLETE
Diffstat (limited to 'ctrack/caf')
-rw-r--r--ctrack/caf/admin.py25
-rw-r--r--ctrack/caf/forms.py7
-rw-r--r--ctrack/caf/migrations/0001_initial.py66
-rw-r--r--ctrack/caf/migrations/0002_auto_20200403_1407.py58
-rw-r--r--ctrack/caf/migrations/0003_auto_20200424_1924.py18
-rw-r--r--ctrack/caf/migrations/0004_auto_20200813_0953.py31
-rw-r--r--ctrack/caf/migrations/0005_applicablesystem_oes_categorisation.py18
-rw-r--r--ctrack/caf/migrations/0006_auto_20200813_1125.py22
-rw-r--r--ctrack/caf/migrations/0007_auto_20200814_1230.py23
-rw-r--r--ctrack/caf/migrations/0008_auto_20200814_1318.py23
-rw-r--r--ctrack/caf/migrations/0009_auto_20200826_1255.py30
-rw-r--r--ctrack/caf/models.py51
-rw-r--r--ctrack/caf/tests/factories.py3
13 files changed, 87 insertions, 288 deletions
diff --git a/ctrack/caf/admin.py b/ctrack/caf/admin.py
index f19e8f4..e633029 100644
--- a/ctrack/caf/admin.py
+++ b/ctrack/caf/admin.py
@@ -5,24 +5,29 @@ from .models import CAF, FileStore, DocumentFile, Grading, ApplicableSystem
class ApplicableSystemListAdmin(admin.ModelAdmin):
model = ApplicableSystem
- list_display = ["name", "organisation", "caf"]
+ list_display = ["name", "function"]
-class ApplicableSystemAdmin(admin.StackedInline):
- model = ApplicableSystem
- max_num = 3
- extra = 1
+# FIXME
+# class ApplicableSystemAdmin(admin.StackedInline):
+# model = ApplicableSystem
+# max_num = 3
+# extra = 1
-def get_caf_name(obj):
- ass = ApplicableSystem.objects.filter(caf=obj).first()
- return f"{ass.organisation.name}_v{obj.version}"
+# FIXME - NOT NEEDED
+# def get_caf_name(obj):
+# ass = ApplicableSystem.objects.filter(caf=obj).first()
+# return f"{ass.organisation.name}_v{obj.version}"
+# FIXME
class CAFAdmin(admin.ModelAdmin):
model = CAF
- inlines = [ApplicableSystemAdmin]
- list_display = [get_caf_name, "quality_grading", "confidence_grading", "file"]
+ # inlines = [ApplicableSystemAdmin]
+
+
+# list_display = ["quality_grading", "confidence_grading", "file"]
admin.site.register(CAF, CAFAdmin)
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py
index 7367ccd..928686d 100644
--- a/ctrack/caf/forms.py
+++ b/ctrack/caf/forms.py
@@ -15,9 +15,10 @@ from django.urls import reverse
from ctrack.caf.models import CAF, ApplicableSystem
from ctrack.organisations.models import Organisation
-CAFCreateInlineFormset = inlineformset_factory(
- CAF, ApplicableSystem, fields=("name", "organisation"), extra=2
-)
+# TODO - Replace this to get inlineformet working
+# CAFCreateInlineFormset = inlineformset_factory(
+# CAF, ApplicableSystem, fields=("name", "organisation"), extra=2
+# )
class ApplicableSystemCreateFromCafForm(forms.Form):
diff --git a/ctrack/caf/migrations/0001_initial.py b/ctrack/caf/migrations/0001_initial.py
index 5e184df..ca65af6 100644
--- a/ctrack/caf/migrations/0001_initial.py
+++ b/ctrack/caf/migrations/0001_initial.py
@@ -1,6 +1,8 @@
-# Generated by Django 2.2.9 on 2020-04-03 14:07
+# Generated by Django 2.2.12 on 2020-08-27 09:40
+import ctrack.caf.models
from django.db import migrations, models
+import django.db.models.deletion
class Migration(migrations.Migration):
@@ -8,6 +10,7 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
+ ('organisations', '0001_initial'),
]
operations = [
@@ -15,49 +18,68 @@ class Migration(migrations.Migration):
name='ApplicableSystem',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('name', models.CharField(max_length=256)),
- ('description', models.TextField(max_length=1000)),
+ ('name', models.CharField(help_text='System name assigned by OES', max_length=256)),
+ ('function', models.TextField(blank=True, help_text='How the system is relevant to delivering or supporting the essential service', max_length=1000, null=True)),
+ ('dft_categorisation', models.CharField(choices=[('CR', 'Critical'), ('IM', 'Important (Legacy use only)')], default='CR', help_text='Refer to documentation for description of these criteria', max_length=2, verbose_name='DfT Categorisation')),
+ ('oes_categorisation', models.CharField(default='NA', help_text="Categorisation based on OES' own internal prioritisation process.", max_length=255, verbose_name='OES Categorisation')),
],
options={
- 'verbose_name': 'Applicable System',
+ 'verbose_name': 'NIS System',
},
),
migrations.CreateModel(
- name='CAF',
+ name='Grading',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('version', models.CharField(blank=True, max_length=10, null=True)),
- ('triage_review_date', models.DateField(blank=True, null=True)),
- ('comments', models.TextField(max_length=1000)),
+ ('descriptor', models.CharField(help_text='Q1, C1, etc', max_length=2)),
+ ('description', models.TextField(max_length=250)),
+ ('type', models.CharField(choices=[('CONFIDENCE', 'Confidence'), ('QUALITY', 'Quality'), ('MISC', 'Misc')], help_text='Type of grading', max_length=20)),
],
- options={
- 'verbose_name': 'CAF',
- },
),
migrations.CreateModel(
- name='DocumentFile',
+ name='FileStore',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('name', models.CharField(max_length=255)),
- ('type', models.IntegerField(choices=[(1, 'Excel'), (2, 'Word'), (3, 'PDF'), (4, 'Hard Copy')], default=1)),
+ ('descriptor', models.CharField(max_length=100)),
+ ('virtual_location', models.CharField(help_text='USB, Rosa, email, etc', max_length=100)),
+ ('physical_location', models.CharField(blank=True, help_text='Cupboard, room, building, etc', max_length=100)),
+ ('physical_location_organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')),
],
),
migrations.CreateModel(
- name='FileStore',
+ name='EssentialService',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('descriptor', models.CharField(max_length=100)),
- ('virtual_location', models.CharField(help_text='USB, Rosa, email, etc', max_length=100)),
- ('physical_location', models.CharField(blank=True, help_text='Cupboard, room, building, etc', max_length=100)),
+ ('name', models.CharField(max_length=256)),
+ ('description', models.CharField(max_length=512)),
+ ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')),
+ ('systems', models.ManyToManyField(to='caf.ApplicableSystem')),
],
),
migrations.CreateModel(
- name='Grading',
+ name='DocumentFile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('descriptor', models.CharField(help_text='Q1, C1, etc', max_length=2)),
- ('description', models.TextField(max_length=250)),
- ('type', models.CharField(choices=[('CONFIDENCE', 'Confidence'), ('QUALITY', 'Quality'), ('MISC', 'Misc')], help_text='Type of grading', max_length=20)),
+ ('name', models.CharField(max_length=255)),
+ ('type', models.IntegerField(choices=[(1, 'Excel'), (2, 'Word'), (3, 'PDF'), (4, 'Hard Copy')], default=1)),
+ ('file_store_location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='caf.FileStore')),
],
),
+ migrations.CreateModel(
+ name='CAF',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('version', models.CharField(blank=True, max_length=10, null=True)),
+ ('triage_review_date', models.DateField(blank=True, null=True)),
+ ('comments', models.TextField(max_length=1000)),
+ ('confidence_grading', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='confidence_grading', to='caf.Grading')),
+ ('file', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.DocumentFile')),
+ ('organisation', models.ForeignKey(on_delete=models.SET(ctrack.caf.models.CAF.get_sentinel_org), to='organisations.Organisation')),
+ ('quality_grading', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='quality_grading', to='caf.Grading')),
+ ('triage_review_inspector', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.Person')),
+ ],
+ options={
+ 'verbose_name': 'CAF',
+ },
+ ),
]
diff --git a/ctrack/caf/migrations/0002_auto_20200403_1407.py b/ctrack/caf/migrations/0002_auto_20200403_1407.py
deleted file mode 100644
index e5963d5..0000000
--- a/ctrack/caf/migrations/0002_auto_20200403_1407.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Generated by Django 2.2.9 on 2020-04-03 14:07
-
-import ctrack.caf.models
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- initial = True
-
- dependencies = [
- ('caf', '0001_initial'),
- ('organisations', '0001_initial'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='filestore',
- name='physical_location_organisation',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation'),
- ),
- migrations.AddField(
- model_name='documentfile',
- name='file_store_location',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='caf.FileStore'),
- ),
- migrations.AddField(
- model_name='caf',
- name='confidence_grading',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='confidence_grading', to='caf.Grading'),
- ),
- migrations.AddField(
- model_name='caf',
- name='file',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.DocumentFile'),
- ),
- migrations.AddField(
- model_name='caf',
- name='quality_grading',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='quality_grading', to='caf.Grading'),
- ),
- migrations.AddField(
- model_name='caf',
- name='triage_review_inspector',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.Person'),
- ),
- migrations.AddField(
- model_name='applicablesystem',
- name='caf',
- field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='applicable_systems', to='caf.CAF'),
- ),
- migrations.AddField(
- model_name='applicablesystem',
- name='organisation',
- field=models.ForeignKey(on_delete=models.SET(ctrack.caf.models.ApplicableSystem.get_sentinel_org), to='organisations.Organisation'),
- ),
- ]
diff --git a/ctrack/caf/migrations/0003_auto_20200424_1924.py b/ctrack/caf/migrations/0003_auto_20200424_1924.py
deleted file mode 100644
index 34613c6..0000000
--- a/ctrack/caf/migrations/0003_auto_20200424_1924.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 2.2.9 on 2020-04-24 19:24
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('caf', '0002_auto_20200403_1407'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='applicablesystem',
- name='description',
- field=models.TextField(blank=True, max_length=1000, null=True),
- ),
- ]
diff --git a/ctrack/caf/migrations/0004_auto_20200813_0953.py b/ctrack/caf/migrations/0004_auto_20200813_0953.py
deleted file mode 100644
index ad1ca96..0000000
--- a/ctrack/caf/migrations/0004_auto_20200813_0953.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# Generated by Django 2.2.12 on 2020-08-13 09:53
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('caf', '0003_auto_20200424_1924'),
- ]
-
- operations = [
- migrations.AlterModelOptions(
- name='applicablesystem',
- options={'verbose_name': 'NIS System'},
- ),
- migrations.RemoveField(
- model_name='applicablesystem',
- name='description',
- ),
- migrations.AddField(
- model_name='applicablesystem',
- name='function',
- field=models.TextField(blank=True, help_text='How the system is relevant to delivering or supporting the essential service', max_length=1000, null=True),
- ),
- migrations.AlterField(
- model_name='applicablesystem',
- name='name',
- field=models.CharField(help_text='System name assigned by OES', max_length=256),
- ),
- ]
diff --git a/ctrack/caf/migrations/0005_applicablesystem_oes_categorisation.py b/ctrack/caf/migrations/0005_applicablesystem_oes_categorisation.py
deleted file mode 100644
index dc8c928..0000000
--- a/ctrack/caf/migrations/0005_applicablesystem_oes_categorisation.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 2.2.12 on 2020-08-13 11:17
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('caf', '0004_auto_20200813_0953'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='applicablesystem',
- name='oes_categorisation',
- field=models.CharField(choices=[('CR', 'Critical'), ('IM', 'Important')], default='CR', max_length=2),
- ),
- ]
diff --git a/ctrack/caf/migrations/0006_auto_20200813_1125.py b/ctrack/caf/migrations/0006_auto_20200813_1125.py
deleted file mode 100644
index 1e97dff..0000000
--- a/ctrack/caf/migrations/0006_auto_20200813_1125.py
+++ /dev/null
@@ -1,22 +0,0 @@
-# Generated by Django 2.2.12 on 2020-08-13 11:25
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('caf', '0005_applicablesystem_oes_categorisation'),
- ]
-
- operations = [
- migrations.RemoveField(
- model_name='applicablesystem',
- name='oes_categorisation',
- ),
- migrations.AddField(
- model_name='applicablesystem',
- name='dft_categorisation',
- field=models.CharField(choices=[('CR', 'Critical'), ('IM', 'Important')], default='CR', help_text='Refer to documentation for description of these criteria', max_length=2, verbose_name='DfT Categorisation'),
- ),
- ]
diff --git a/ctrack/caf/migrations/0007_auto_20200814_1230.py b/ctrack/caf/migrations/0007_auto_20200814_1230.py
deleted file mode 100644
index 68a12bd..0000000
--- a/ctrack/caf/migrations/0007_auto_20200814_1230.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Generated by Django 2.2.12 on 2020-08-14 12:30
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('caf', '0006_auto_20200813_1125'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='applicablesystem',
- name='oes_categorisation',
- field=models.CharField(default='', help_text="Categorisation based on OES' own internal prioritisation process.", max_length=255, verbose_name='OES Categorisation'),
- ),
- migrations.AlterField(
- model_name='applicablesystem',
- name='dft_categorisation',
- field=models.CharField(choices=[('CR', 'Critical'), ('IM', 'Important (Legacy use only)')], default='CR', help_text='Refer to documentation for description of these criteria', max_length=2, verbose_name='DfT Categorisation'),
- ),
- ]
diff --git a/ctrack/caf/migrations/0008_auto_20200814_1318.py b/ctrack/caf/migrations/0008_auto_20200814_1318.py
deleted file mode 100644
index 90f188f..0000000
--- a/ctrack/caf/migrations/0008_auto_20200814_1318.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Generated by Django 2.2.12 on 2020-08-14 13:18
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('caf', '0007_auto_20200814_1230'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='applicablesystem',
- name='essential_service',
- field=models.CharField(default='NA', help_text='Name of the essential service which the system suppports.', max_length=255, verbose_name='Essential Service'),
- ),
- migrations.AlterField(
- model_name='applicablesystem',
- name='oes_categorisation',
- field=models.CharField(default='NA', help_text="Categorisation based on OES' own internal prioritisation process.", max_length=255, verbose_name='OES Categorisation'),
- ),
- ]
diff --git a/ctrack/caf/migrations/0009_auto_20200826_1255.py b/ctrack/caf/migrations/0009_auto_20200826_1255.py
deleted file mode 100644
index 6611b59..0000000
--- a/ctrack/caf/migrations/0009_auto_20200826_1255.py
+++ /dev/null
@@ -1,30 +0,0 @@
-# Generated by Django 2.2.12 on 2020-08-26 12:55
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('organisations', '0011_auto_20200531_1441'),
- ('caf', '0008_auto_20200814_1318'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='applicablesystem',
- name='essential_service',
- field=models.CharField(default='NA', help_text='Description of the essential service which the system suppports.', max_length=255, verbose_name='Essential Service'),
- ),
- migrations.CreateModel(
- name='EssentialService',
- fields=[
- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('name', models.CharField(max_length=256)),
- ('description', models.CharField(max_length=512)),
- ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')),
- ('systems', models.ManyToManyField(to='caf.ApplicableSystem')),
- ],
- ),
- ]
diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py
index 892c2cf..fc56c30 100644
--- a/ctrack/caf/models.py
+++ b/ctrack/caf/models.py
@@ -45,13 +45,6 @@ class DocumentFile(models.Model):
class ApplicableSystem(models.Model):
- CRITICAL = "CR"
- IMPORTANT = "IM"
- SYSTEM_CATEGORISATION = (
- (CRITICAL, "Critical"),
- (IMPORTANT, "Important (Legacy use only)"),
- )
-
def get_sentinel_org():
"""
We need this so that we can ensure models.SET() is applied with a callable
@@ -60,6 +53,13 @@ class ApplicableSystem(models.Model):
"""
return Organisation.objects.get_or_create(name="DELETED ORGANISATION")[0]
+ CRITICAL = "CR"
+ IMPORTANT = "IM"
+ SYSTEM_CATEGORISATION = (
+ (CRITICAL, "Critical"),
+ (IMPORTANT, "Important (Legacy use only)"),
+ )
+
name = models.CharField(max_length=256, help_text="System name assigned by OES")
function = models.TextField(
max_length=1000,
@@ -68,22 +68,6 @@ class ApplicableSystem(models.Model):
help_text="How the system is relevant to delivering or supporting the "
"essential service",
)
- organisation = models.ForeignKey(
- Organisation, on_delete=models.SET(get_sentinel_org)
- )
- caf = models.ForeignKey(
- "CAF",
- on_delete=models.CASCADE,
- blank=True,
- null=True,
- related_name="applicable_systems",
- )
- essential_service = models.CharField(
- max_length=255,
- default="NA",
- verbose_name="Essential Service",
- help_text="Description of the essential service which the system suppports.",
- )
dft_categorisation = models.CharField(
max_length=2,
choices=SYSTEM_CATEGORISATION,
@@ -111,6 +95,14 @@ class ApplicableSystem(models.Model):
class CAF(models.Model):
+ def get_sentinel_org():
+ """
+ We need this so that we can ensure models.SET() is applied with a callable
+ to handle when Users are deleted from the system, preventing the Organisation
+ objects related to them being deleted also.
+ """
+ return Organisation.objects.get_or_create(name="DELETED ORGANISATION")[0]
+
quality_grading = models.ForeignKey(
Grading,
on_delete=models.CASCADE,
@@ -129,6 +121,9 @@ class CAF(models.Model):
DocumentFile, on_delete=models.CASCADE, blank=True, null=True
)
version = models.CharField(max_length=10, blank=True, null=True)
+ organisation = models.ForeignKey(
+ Organisation, on_delete=models.SET(get_sentinel_org)
+ )
triage_review_date = models.DateField(blank=True, null=True)
triage_review_inspector = models.ForeignKey(
Person, on_delete=models.CASCADE, blank=True, null=True
@@ -147,17 +142,17 @@ class CAF(models.Model):
"""
return ApplicableSystem.objects.filter(caf=self)
- def organisation(self):
- first_ass = ApplicableSystem.objects.filter(caf=self).first()
- return first_ass.organisation
+ # FIXME remove once we know we don't need it
+ # def organisation(self):
+ # first_ass = ApplicableSystem.objects.filter(caf=self).first()
+ # return first_ass.organisation
def sub_mode(self):
return self.organisation().submode
def __str__(self):
# Get the organisation and applicable system
- ass = ApplicableSystem.objects.filter(caf=self).first()
- return f"CAF | {ass.organisation.name}_v{self.version}"
+ return f"CAF | {self.organisation.name}_v{self.version}"
class EssentialService(models.Model):
diff --git a/ctrack/caf/tests/factories.py b/ctrack/caf/tests/factories.py
index 3c62307..7aaf716 100644
--- a/ctrack/caf/tests/factories.py
+++ b/ctrack/caf/tests/factories.py
@@ -10,6 +10,7 @@ from ctrack.organisations.tests.factories import OrganisationFactory, PersonFact
class CAFFactory(factory.DjangoModelFactory):
quality_grading = factory.SubFactory("ctrack.caf.tests.factories.GradingFactory")
confidence_grading = factory.SubFactory("ctrack.caf.tests.factories.GradingFactory")
+ organisation = factory.SubFactory("ctrack.organisations.tests.OrganisationFactory")
file = None
version = Faker("bothify", text="??##", letters="ABCD")
triage_review_date = Faker("date_object")
@@ -29,8 +30,6 @@ class ApplicableSystemFactory(factory.DjangoModelFactory):
function = Faker(
"paragraph", nb_sentences=4, variable_nb_sentences=True, ext_word_list=None
)
- organisation = factory.SubFactory(OrganisationFactory)
- caf = factory.SubFactory("ctrack.caf.tests.factories.CAFFactory")
dft_categorisation = "CR"
class Meta: