From 6f4ea7ef9018e2e1df396f16aa4080dcee3ef6df Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 26 Aug 2020 13:40:13 +0100 Subject: started the rebuild --- ctrack/organisations/tests/test_models.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ctrack/organisations') 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 -- cgit v1.2.3 From bc556144060dcbbf1d89279b9c5f3d54fa271b6b Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 26 Aug 2020 15:00:09 +0100 Subject: first passing test - making essential service an object --- ctrack/organisations/tests/test_models.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py index 8287e97..09d4f12 100644 --- a/ctrack/organisations/tests/test_models.py +++ b/ctrack/organisations/tests/test_models.py @@ -1,8 +1,14 @@ +import random + import pytest + from slugify import slugify from ctrack.organisations.models import IncidentReport, Organisation +from ctrack.caf.models import CAF, Grading +from ctrack.caf.tests.factories import ApplicableSystemFactory from ctrack.caf.models import EssentialService +from ctrack.core.utils import fnames pytestmark = pytest.mark.django_db @@ -24,6 +30,22 @@ def test_new_address(addr): assert addr.organisation.name -def test_essential_service(): - es = EssentialService() - assert es +def test_essential_service(org): + q1 = Grading.objects.create(descriptor="Q1", description="baws", type="QUALITY") + c1 = Grading.objects.create( + descriptor="C1", description="baws_c", type="CONFIDENCE" + ) + caf = CAF.objects.create( + quality_grading=q1, + confidence_grading=c1, + triage_review_date=None, + triage_review_inspector=None, + ) + ass = ApplicableSystemFactory.create( + name=random.choice(fnames), organisation=org, caf=caf, + ) + es = EssentialService.objects.create( + name="Test ES", description="Test ES Description", organisation=org + ) + es.systems.add(ass) + assert es.systems.first().organisation.name == org.name -- cgit v1.2.3 From 36759e44bc59747256332809097342a32ab6db19 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 26 Aug 2020 15:23:37 +0100 Subject: further asserts added to the test --- ctrack/organisations/models.py | 7 +++++++ ctrack/organisations/tests/test_models.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 9eb0a23..78e4801 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -155,6 +155,13 @@ class Organisation(models.Model): def applicable_systems(self): return self.applicablesystem_set.all() + def systems(self): + ess = self.essentialservice_set.all() + out = [] + for es in ess: + out.extend(list(es.systems.all())) + return out + class Address(models.Model): organisation = models.ForeignKey( diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py index 09d4f12..103ead4 100644 --- a/ctrack/organisations/tests/test_models.py +++ b/ctrack/organisations/tests/test_models.py @@ -44,8 +44,14 @@ def test_essential_service(org): ass = ApplicableSystemFactory.create( name=random.choice(fnames), organisation=org, caf=caf, ) + ass2 = ApplicableSystemFactory.create( + name=random.choice(fnames), organisation=org, caf=caf, + ) es = EssentialService.objects.create( name="Test ES", description="Test ES Description", organisation=org ) - es.systems.add(ass) + es.systems.add(ass, ass2) assert es.systems.first().organisation.name == org.name + assert es.name == "Test ES" + assert es.systems.count() == 2 + assert ass.name in [s.name for s in org.systems()] -- cgit v1.2.3 From ef287a9397cd911d55a37eb98934c203a59a8154 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 27 Aug 2020 11:03:14 +0100 Subject: massive - removed migrations and reform db schema - NOT COMPLETE --- ctrack/organisations/admin.py | 6 ++ ctrack/organisations/migrations/0001_initial.py | 114 ++++++++++++++------- .../migrations/0002_auto_20200403_1407.py | 44 -------- .../migrations/0003_auto_20200424_1607.py | 18 ---- .../migrations/0004_auto_20200513_1441.py | 18 ---- .../migrations/0005_auto_20200525_1502.py | 29 ------ .../migrations/0006_incidentreport.py | 35 ------- .../migrations/0007_auto_20200529_1520.py | 23 ----- .../migrations/0008_auto_20200529_1545.py | 38 ------- .../0009_incidentreport_person_involved.py | 18 ---- .../migrations/0010_auto_20200529_1602.py | 18 ---- .../migrations/0011_auto_20200531_1441.py | 19 ---- 12 files changed, 84 insertions(+), 296 deletions(-) delete mode 100644 ctrack/organisations/migrations/0002_auto_20200403_1407.py delete mode 100644 ctrack/organisations/migrations/0003_auto_20200424_1607.py delete mode 100644 ctrack/organisations/migrations/0004_auto_20200513_1441.py delete mode 100644 ctrack/organisations/migrations/0005_auto_20200525_1502.py delete mode 100644 ctrack/organisations/migrations/0006_incidentreport.py delete mode 100644 ctrack/organisations/migrations/0007_auto_20200529_1520.py delete mode 100644 ctrack/organisations/migrations/0008_auto_20200529_1545.py delete mode 100644 ctrack/organisations/migrations/0009_incidentreport_person_involved.py delete mode 100644 ctrack/organisations/migrations/0010_auto_20200529_1602.py delete mode 100644 ctrack/organisations/migrations/0011_auto_20200531_1441.py (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py index 203baa9..d3e6284 100644 --- a/ctrack/organisations/admin.py +++ b/ctrack/organisations/admin.py @@ -1,5 +1,7 @@ from django.contrib import admin +from ctrack.caf.models import CAF + from .models import ( Address, AddressType, @@ -18,6 +20,10 @@ def get_organisation_name(person): return Organisation.objects.filter(person__id=person.id).first().name +def get_first_caf(org): + return CAF.objects.filter(organisation__id=org.id).first().version + + # We need this to ensure the column header in the admin does't read the func name get_organisation_name.short_description = "Organisation" diff --git a/ctrack/organisations/migrations/0001_initial.py b/ctrack/organisations/migrations/0001_initial.py index a420fa1..c5ab495 100644 --- a/ctrack/organisations/migrations/0001_initial.py +++ b/ctrack/organisations/migrations/0001_initial.py @@ -1,5 +1,6 @@ -# 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 django.contrib.auth from django.db import migrations, models import django.db.models.deletion import django_extensions.db.fields @@ -13,23 +14,6 @@ class Migration(migrations.Migration): ] operations = [ - migrations.CreateModel( - name='Address', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('line1', models.CharField(max_length=255)), - ('line2', models.CharField(blank=True, max_length=255)), - ('line3', models.CharField(blank=True, max_length=255)), - ('city', models.CharField(max_length=100)), - ('county', models.CharField(blank=True, max_length=100)), - ('postcode', models.CharField(max_length=10)), - ('country', models.CharField(max_length=100)), - ('other_details', models.CharField(blank=True, max_length=255)), - ], - options={ - 'verbose_name_plural': 'Addresses', - }, - ), migrations.CreateModel( name='AddressType', fields=[ @@ -50,30 +34,15 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=255)), ('slug', django_extensions.db.fields.AutoSlugField(blank=True, editable=False, populate_from=['name'])), - ('oes', models.BooleanField()), + ('oes', models.BooleanField(default=True)), ('designation_type', models.IntegerField(choices=[(1, 'Automatic'), (2, 'Reserve Power'), (3, 'NA')], default=1)), ('registered_company_name', models.CharField(blank=True, max_length=255)), ('registered_company_number', models.CharField(blank=True, max_length=100)), ('date_updated', models.DateField(auto_now=True)), - ('comments', models.TextField(max_length=500)), + ('comments', models.TextField(blank=True, max_length=500, null=True)), ('active', models.BooleanField(default=True)), ], ), - migrations.CreateModel( - name='Role', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ], - ), - migrations.CreateModel( - name='Submode', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('descriptor', models.CharField(max_length=100)), - ('mode', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Mode')), - ], - ), migrations.CreateModel( name='Person', fields=[ @@ -100,10 +69,83 @@ class Migration(migrations.Migration): ('comments', models.TextField(blank=True, max_length=1000)), ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')), ('predecessor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='previous_person', to='organisations.Person')), - ('role', models.ManyToManyField(to='organisations.Role')), ], options={ 'verbose_name_plural': 'People', }, ), + migrations.CreateModel( + name='Role', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Submode', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('descriptor', models.CharField(max_length=100)), + ('mode', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Mode')), + ], + ), + migrations.CreateModel( + name='Stakeholder', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Person')), + ], + ), + migrations.AddField( + model_name='person', + name='role', + field=models.ManyToManyField(to='organisations.Role'), + ), + migrations.AddField( + model_name='organisation', + name='submode', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.Submode'), + ), + migrations.CreateModel( + name='IncidentReport', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('person_involved', models.CharField(blank=True, max_length=100, verbose_name='Name of person reporting/detecting incident')), + ('role', models.CharField(blank=True, help_text='Role of person reporting/detecting incident', max_length=100)), + ('phone_number', models.CharField(max_length=30)), + ('email', models.EmailField(max_length=254)), + ('internal_incident_number', models.CharField(blank=True, max_length=30)), + ('date_time_incident_detected', models.DateTimeField(verbose_name='Date/Time incident detected')), + ('date_time_incident_reported', models.DateTimeField(auto_now=True, verbose_name='Date/Time incident reported')), + ('incident_type', models.CharField(choices=[('Cyber', 'Cyber'), ('Non-Cyber', 'Non-Cyber'), ('Both', 'Both'), ('Power Outage', 'Power Outage')], help_text='This can be appoximate', max_length=20)), + ('incident_status', models.CharField(choices=[('Detected', 'Detected'), ('Suspected', 'Suspected'), ('Resolved', 'Resolved')], max_length=20)), + ('incident_stage', models.CharField(choices=[('Ongoing', 'Ongoing'), ('Ended', 'Ended'), ('Ongoing but managed', 'Ongoing but managed')], max_length=20)), + ('summary', models.TextField(help_text='Please provide a summary of your understanding of the incident, including any impact to services and/or users.')), + ('mitigations', models.TextField(help_text='What investigations and/or mitigations have you or a third party performed or plan to perform?', verbose_name='Investigations or mitigations')), + ('others_informed', models.TextField(help_text='Who else has been informed about this incident?(CSIRT, NCSC, NCA, etc)', verbose_name='Others parties informed')), + ('next_steps', models.TextField(help_text='What are your planned next steps?', verbose_name='Planned next steps')), + ('dft_handle_status', models.CharField(choices=[('QUEUED', 'QUEUED'), ('REVIEWING', 'REVIEWING'), ('WAITING', 'WAITING'), ('COMPLETED', 'COMPLETED')], default='QUEUED', max_length=20)), + ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')), + ('reporting_person', models.ForeignKey(on_delete=models.SET(django.contrib.auth.get_user_model), to='organisations.Person', verbose_name='Person reporting the incident')), + ], + ), + migrations.CreateModel( + name='Address', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('line1', models.CharField(max_length=255)), + ('line2', models.CharField(blank=True, max_length=255)), + ('line3', models.CharField(blank=True, max_length=255)), + ('city', models.CharField(max_length=100)), + ('county', models.CharField(blank=True, max_length=100)), + ('postcode', models.CharField(max_length=10)), + ('country', models.CharField(max_length=100)), + ('other_details', models.CharField(blank=True, max_length=255)), + ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='organisations.Organisation')), + ('type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.AddressType', verbose_name='Address Type')), + ], + options={ + 'verbose_name_plural': 'Addresses', + }, + ), ] diff --git a/ctrack/organisations/migrations/0002_auto_20200403_1407.py b/ctrack/organisations/migrations/0002_auto_20200403_1407.py deleted file mode 100644 index d9f3aed..0000000 --- a/ctrack/organisations/migrations/0002_auto_20200403_1407.py +++ /dev/null @@ -1,44 +0,0 @@ -# Generated by Django 2.2.9 on 2020-04-03 14:07 - -import ctrack.organisations.models -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('organisations', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='person', - name='updated_by', - field=models.ForeignKey(on_delete=models.SET(ctrack.organisations.models.Person.get_sentinel_user), to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='organisation', - name='submode', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organisations.Submode'), - ), - migrations.AddField( - model_name='organisation', - name='updated_by', - field=models.ForeignKey(on_delete=models.SET(ctrack.organisations.models.Organisation.get_sentinel_user), to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='address', - name='organisation', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='organisations.Organisation'), - ), - migrations.AddField( - model_name='address', - name='type', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.AddressType', verbose_name='Address Type'), - ), - ] diff --git a/ctrack/organisations/migrations/0003_auto_20200424_1607.py b/ctrack/organisations/migrations/0003_auto_20200424_1607.py deleted file mode 100644 index 75268a0..0000000 --- a/ctrack/organisations/migrations/0003_auto_20200424_1607.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.9 on 2020-04-24 16:07 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0002_auto_20200403_1407'), - ] - - operations = [ - migrations.AlterField( - model_name='organisation', - name='comments', - field=models.TextField(blank=True, max_length=500, null=True), - ), - ] diff --git a/ctrack/organisations/migrations/0004_auto_20200513_1441.py b/ctrack/organisations/migrations/0004_auto_20200513_1441.py deleted file mode 100644 index 180211a..0000000 --- a/ctrack/organisations/migrations/0004_auto_20200513_1441.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.5 on 2020-05-13 14:41 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0003_auto_20200424_1607'), - ] - - operations = [ - migrations.AlterField( - model_name='organisation', - name='oes', - field=models.BooleanField(default=True), - ), - ] diff --git a/ctrack/organisations/migrations/0005_auto_20200525_1502.py b/ctrack/organisations/migrations/0005_auto_20200525_1502.py deleted file mode 100644 index 921fdbb..0000000 --- a/ctrack/organisations/migrations/0005_auto_20200525_1502.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 3.0.5 on 2020-05-25 15:02 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0004_auto_20200513_1441'), - ] - - operations = [ - migrations.RemoveField( - model_name='organisation', - name='updated_by', - ), - migrations.RemoveField( - model_name='person', - name='updated_by', - ), - migrations.CreateModel( - name='Stakeholder', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Person')), - ], - ), - ] diff --git a/ctrack/organisations/migrations/0006_incidentreport.py b/ctrack/organisations/migrations/0006_incidentreport.py deleted file mode 100644 index 0528aaa..0000000 --- a/ctrack/organisations/migrations/0006_incidentreport.py +++ /dev/null @@ -1,35 +0,0 @@ -# Generated by Django 2.2.12 on 2020-05-29 12:56 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0005_auto_20200525_1502'), - ] - - operations = [ - migrations.CreateModel( - name='IncidentReport', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('role', models.CharField(help_text='Please identify your role', max_length=100)), - ('phone_number', models.CharField(max_length=30)), - ('email', models.EmailField(max_length=254)), - ('internal_incident_number', models.CharField(blank=True, max_length=30)), - ('date_time_incident_detected', models.DateTimeField(help_text='This can be approximate', verbose_name='Date/Time incident detected')), - ('date_time_incident_reported', models.DateTimeField(verbose_name='Date/Time incident reported')), - ('incident_type', models.CharField(choices=[('cyber', 'Cyber'), ('non-cyber', 'Non-Cyber'), ('both', 'Both'), ('power', 'Power Outage')], help_text='This can be appoximate', max_length=10)), - ('incident_status', models.CharField(choices=[('detected', 'Detected'), ('suspected', 'Suspected'), ('resolved', 'Resolved')], max_length=10)), - ('incident_stage', models.CharField(choices=[('ongoing', 'Ongoing'), ('ended', 'Ended'), ('managed', 'Ongoing but managed')], max_length=10)), - ('summary', models.TextField(help_text='Please provide a summary of your understanding of the incident, including any impact to services and/or users.')), - ('mitigations', models.TextField(help_text='What investigations and/or mitigations have you or a third party performed or plan to perform?', verbose_name='Investigations or mitigations')), - ('others_informed', models.TextField(help_text='Who else has been informed about this incident?(CSIRT, NCSC, NCA, etc)', verbose_name='Others parties informed')), - ('next_steps', models.TextField(help_text='What are your planned next steps?', verbose_name='Planned next steps')), - ('organisation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Organisation')), - ('reporting_person', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.Person', verbose_name='Person reporting the incident')), - ], - ), - ] diff --git a/ctrack/organisations/migrations/0007_auto_20200529_1520.py b/ctrack/organisations/migrations/0007_auto_20200529_1520.py deleted file mode 100644 index 59a5089..0000000 --- a/ctrack/organisations/migrations/0007_auto_20200529_1520.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.2.12 on 2020-05-29 15:20 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0006_incidentreport'), - ] - - operations = [ - migrations.AddField( - model_name='incidentreport', - name='dft_handle_status', - field=models.CharField(choices=[('queued', 'QUEUED'), ('reviewing', 'REVIEWING'), ('waiting', 'WAITING'), ('completed', 'COMPLETE')], default='queued', max_length=20), - ), - migrations.AlterField( - model_name='incidentreport', - name='date_time_incident_reported', - field=models.DateTimeField(auto_now=True, verbose_name='Date/Time incident reported'), - ), - ] diff --git a/ctrack/organisations/migrations/0008_auto_20200529_1545.py b/ctrack/organisations/migrations/0008_auto_20200529_1545.py deleted file mode 100644 index 1c4cec6..0000000 --- a/ctrack/organisations/migrations/0008_auto_20200529_1545.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 2.2.12 on 2020-05-29 15:45 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0007_auto_20200529_1520'), - ] - - operations = [ - migrations.AlterField( - model_name='incidentreport', - name='date_time_incident_detected', - field=models.DateTimeField(verbose_name='Date/Time incident detected'), - ), - migrations.AlterField( - model_name='incidentreport', - name='dft_handle_status', - field=models.CharField(choices=[('QUEUED', 'QUEUED'), ('REVIEWING', 'REVIEWING'), ('WAITING', 'WAITING'), ('COMPLETED', 'COMPLETED')], default='QUEUED', max_length=20), - ), - migrations.AlterField( - model_name='incidentreport', - name='incident_stage', - field=models.CharField(choices=[('Ongoing', 'Ongoing'), ('Ended', 'Ended'), ('Ongoing but managed', 'Ongoing but managed')], max_length=20), - ), - migrations.AlterField( - model_name='incidentreport', - name='incident_status', - field=models.CharField(choices=[('Detected', 'Detected'), ('Suspected', 'Suspected'), ('Resolved', 'Resolved')], max_length=20), - ), - migrations.AlterField( - model_name='incidentreport', - name='incident_type', - field=models.CharField(choices=[('Cyber', 'Cyber'), ('Non-Cyber', 'Non-Cyber'), ('Both', 'Both'), ('Power Outage', 'Power Outage')], help_text='This can be appoximate', max_length=20), - ), - ] diff --git a/ctrack/organisations/migrations/0009_incidentreport_person_involved.py b/ctrack/organisations/migrations/0009_incidentreport_person_involved.py deleted file mode 100644 index ea4799c..0000000 --- a/ctrack/organisations/migrations/0009_incidentreport_person_involved.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.12 on 2020-05-29 16:01 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0008_auto_20200529_1545'), - ] - - operations = [ - migrations.AddField( - model_name='incidentreport', - name='person_involved', - field=models.CharField(blank=True, max_length=100, verbose_name='Name of person reporting/detecting incident'), - ), - ] diff --git a/ctrack/organisations/migrations/0010_auto_20200529_1602.py b/ctrack/organisations/migrations/0010_auto_20200529_1602.py deleted file mode 100644 index 2986d36..0000000 --- a/ctrack/organisations/migrations/0010_auto_20200529_1602.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.12 on 2020-05-29 16:02 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0009_incidentreport_person_involved'), - ] - - operations = [ - migrations.AlterField( - model_name='incidentreport', - name='role', - field=models.CharField(blank=True, help_text='Role of person reporting/detecting incident', max_length=100), - ), - ] diff --git a/ctrack/organisations/migrations/0011_auto_20200531_1441.py b/ctrack/organisations/migrations/0011_auto_20200531_1441.py deleted file mode 100644 index 3dced7d..0000000 --- a/ctrack/organisations/migrations/0011_auto_20200531_1441.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.12 on 2020-05-31 14:41 - -import django.contrib.auth -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('organisations', '0010_auto_20200529_1602'), - ] - - operations = [ - migrations.AlterField( - model_name='incidentreport', - name='reporting_person', - field=models.ForeignKey(on_delete=models.SET(django.contrib.auth.get_user_model), to='organisations.Person', verbose_name='Person reporting the incident'), - ), - ] -- cgit v1.2.3 From 0b1c397af82abd41e4379bd1f1eab490fe22db38 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 27 Aug 2020 15:24:15 +0100 Subject: further work trying to get user views working --- ctrack/organisations/models.py | 7 +++++++ .../templates/organisations/organisation_detail.html | 12 +----------- ctrack/organisations/views.py | 5 ++++- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 78e4801..1c914b5 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -162,6 +162,13 @@ class Organisation(models.Model): out.extend(list(es.systems.all())) return out + def systems_for_each_essential_service(self): + ess = self.essentialservice_set.all() + out = [] + for es in ess: + out.extend(es.systems.all()) + return out + class Address(models.Model): organisation = models.ForeignKey( diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index 8c9ac3b..0e981b9 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -99,17 +99,7 @@
-
OES EngagementsAdd - new...
-
- - {% if engagement_events|length > 0 %} - {% for event in engagement_events %} - - - - - {% endfor %} +
OES EngagementsAdd new...
{{ event.type}}{{ event.short_description }}
{% if engagement_events|length > 0 %} {% for event in engagement_events %} {% endfor %} {% else %} Add new... diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 394966a..3f91e2f 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -10,6 +10,7 @@ from ctrack.register.models import EngagementEvent from .forms import AddressInlineFormSet, IncidentReportForm, OrganisationCreateForm from .models import IncidentReport, Organisation, Person +from ctrack.caf.models import EssentialService class PersonListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): @@ -66,6 +67,7 @@ class OrganisationDetailView(LoginRequiredMixin, PermissionRequiredMixin, Detail org = kwargs["object"] peoples = org.person_set.all() engagement_events = EngagementEvent.objects.filter(participants__in=peoples) + essential_services = EssentialService.objects.filter(organisation=org) no_addr = org.addresses.count() if no_addr > 1: context["no_addr"] = no_addr @@ -77,9 +79,10 @@ class OrganisationDetailView(LoginRequiredMixin, PermissionRequiredMixin, Detail context["addr"] = addr people = org.person_set.all() context["people"] = people - applicable_systems = org.applicablesystem_set.all() + applicable_systems = org.systems_for_each_essential_service() context["applicable_systems"] = applicable_systems context["engagement_events"] = engagement_events + context["essential_services"] = essential_services return context -- cgit v1.2.3 From 3913f7ead10b6f98c3f9b4e5882336f75b6f1576 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 28 Aug 2020 11:25:10 +0100 Subject: fixed some more view bugs related to db redesign --- ctrack/organisations/models.py | 10 ++++------ .../templates/organisations/organisation_detail.html | 2 +- ctrack/organisations/views.py | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 1c914b5..f91dabf 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -153,20 +153,18 @@ class Organisation(models.Model): return self.person_set.filter(primary_nis_contact=True) def applicable_systems(self): - return self.applicablesystem_set.all() - - def systems(self): + # return self.applicablesystem_set.all() ess = self.essentialservice_set.all() out = [] for es in ess: - out.extend(list(es.systems.all())) + out.extend(es.systems.all()) return out - def systems_for_each_essential_service(self): + def systems(self): ess = self.essentialservice_set.all() out = [] for es in ess: - out.extend(es.systems.all()) + out.extend(list(es.systems.all())) return out diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index 0e981b9..9ece192 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -79,7 +79,7 @@ diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 3f91e2f..7652783 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -79,7 +79,7 @@ class OrganisationDetailView(LoginRequiredMixin, PermissionRequiredMixin, Detail context["addr"] = addr people = org.person_set.all() context["people"] = people - applicable_systems = org.systems_for_each_essential_service() + applicable_systems = org.applicable_systems() context["applicable_systems"] = applicable_systems context["engagement_events"] = engagement_events context["essential_services"] = essential_services -- cgit v1.2.3 From c27cfbc3cb2eb15eed0e1012f5bb8a537d6d9d5e Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 28 Aug 2020 11:46:15 +0100 Subject: fixed a failing new test (essential service) --- ctrack/organisations/tests/test_models.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py index 103ead4..108d0ce 100644 --- a/ctrack/organisations/tests/test_models.py +++ b/ctrack/organisations/tests/test_models.py @@ -37,21 +37,18 @@ def test_essential_service(org): ) caf = CAF.objects.create( quality_grading=q1, + organisation=org, confidence_grading=c1, triage_review_date=None, triage_review_inspector=None, ) - ass = ApplicableSystemFactory.create( - name=random.choice(fnames), organisation=org, caf=caf, - ) - ass2 = ApplicableSystemFactory.create( - name=random.choice(fnames), organisation=org, caf=caf, - ) + ass = ApplicableSystemFactory.create(name=random.choice(fnames), caf=caf,) + ass2 = ApplicableSystemFactory.create(name=random.choice(fnames), caf=caf,) es = EssentialService.objects.create( name="Test ES", description="Test ES Description", organisation=org ) es.systems.add(ass, ass2) - assert es.systems.first().organisation.name == org.name + assert es.organisation.name == org.name assert es.name == "Test ES" assert es.systems.count() == 2 assert ass.name in [s.name for s in org.systems()] -- cgit v1.2.3 From 9e9f4b37c3efd969d6d9f73dad19b78e4c62d134 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 28 Aug 2020 12:20:44 +0100 Subject: started adding new content to org detail page - ess service --- .../organisations/organisation_detail.html | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index 9ece192..ac73c20 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -95,6 +95,33 @@ + +
+
+
+
+
Essential Services
+
+
{{ event.type}} {{ event.short_description }}
{{ ass.name }} {{ ass.function }}
- + {{ ass.caf }} | Edit System
+ {% if applicable_systems|length > 0 %} + {% for es in essential_services %} + + + + + {% endfor %} + {% else %} +

button to create new one here

+ {% endif %} +
{{ es.name }}{{ es.description }}
+ | Edit System +
+
+
+
+
+ +
-- cgit v1.2.3 From 055b50d7675505d60c0faa8bea900c9e553b7f2b Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 28 Aug 2020 12:22:05 +0100 Subject: reordered cards --- .../organisations/organisation_detail.html | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'ctrack/organisations') diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index ac73c20..a86adf1 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -65,29 +65,25 @@
+
-
NIS Systems Add - new...
+
Essential Services
{% if applicable_systems|length > 0 %} - {% for ass in applicable_systems %} + {% for es in essential_services %} - - + {% endfor %} {% else %} - Add - new... +

button to create new one here

{% endif %}
{{ ass.name }}{{ ass.function }}
- - {{ ass.caf }} - | Edit System +
{{ es.name }}{{ es.description }}
+ | Edit System
@@ -100,20 +96,25 @@
-
Essential Services
+
NIS Systems Add + new...
{% if applicable_systems|length > 0 %} - {% for es in essential_services %} + {% for ass in applicable_systems %} - - + {% endfor %} {% else %} -

button to create new one here

+ Add + new... {% endif %}
{{ es.name }}{{ es.description }}
- | Edit System +
{{ ass.name }}{{ ass.function }}
+ + {{ ass.caf }} + | Edit System
@@ -122,6 +123,7 @@
+
-- cgit v1.2.3