diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/admin.py | 24 | ||||
-rw-r--r-- | ctrack/caf/forms.py | 4 | ||||
-rw-r--r-- | ctrack/caf/migrations/0003_auto_20200221_2104.py | 33 | ||||
-rw-r--r-- | ctrack/caf/migrations/0004_auto_20200221_2106.py | 24 | ||||
-rw-r--r-- | ctrack/caf/migrations/0005_auto_20200221_2115.py | 39 | ||||
-rw-r--r-- | ctrack/caf/migrations/0006_auto_20200221_2120.py | 22 | ||||
-rw-r--r-- | ctrack/caf/migrations/0007_auto_20200221_2122.py | 18 | ||||
-rw-r--r-- | ctrack/caf/models.py | 51 |
8 files changed, 201 insertions, 14 deletions
diff --git a/ctrack/caf/admin.py b/ctrack/caf/admin.py index e423044..139b013 100644 --- a/ctrack/caf/admin.py +++ b/ctrack/caf/admin.py @@ -1,8 +1,30 @@ from django.contrib import admin from .models import CAF, CAFFileStore, DocumentFile, Ranking +from .models import ConfidenceAssessment +from .models import EssentialService -admin.site.register(CAF) + +class EssentialServiceListAdmin(admin.ModelAdmin): + model = EssentialService + list_display = ["name", "organisation", "caf"] + + +class EssentialServiceAdmin(admin.StackedInline): + model = EssentialService + max_num = 3 + extra = 1 + + +class CAFAdmin(admin.ModelAdmin): + model = CAF + inlines = [EssentialServiceAdmin] + list_display = ["owner", "triage_ranking", "confidence_assessment", "file"] + + +admin.site.register(CAF, CAFAdmin) admin.site.register(CAFFileStore) admin.site.register(DocumentFile) admin.site.register(Ranking) +admin.site.register(ConfidenceAssessment) +admin.site.register(EssentialService, EssentialServiceListAdmin) diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py index 34826be..8ef9793 100644 --- a/ctrack/caf/forms.py +++ b/ctrack/caf/forms.py @@ -24,7 +24,7 @@ class CAFForm(forms.ModelForm): class Meta: model = CAF - fields = ["owner", "essential_system", "file"] + fields = ["owner", "file"] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -35,7 +35,7 @@ class CAFForm(forms.ModelForm): self.helper.form_class = "form-group" self.helper.form_method = "post" self.helper.layout = Layout( - Fieldset("Create/Edit CAF", "owner", "essential_system", "file"), + Fieldset("Create/Edit CAF", "owner", "file"), ButtonHolder(Submit("submit", "Submit"), Button("cancel", "Cancel")), ) diff --git a/ctrack/caf/migrations/0003_auto_20200221_2104.py b/ctrack/caf/migrations/0003_auto_20200221_2104.py new file mode 100644 index 0000000..4726a28 --- /dev/null +++ b/ctrack/caf/migrations/0003_auto_20200221_2104.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.9 on 2020-02-21 21:04 + +import ctrack.caf.models +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisations', '0004_auto_20200220_1634'), + ('caf', '0002_auto_20200220_1434'), + ] + + operations = [ + migrations.RemoveField( + model_name='caf', + name='essential_system', + ), + 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.TextField(max_length=1000)), + ('caf', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='caf.CAF')), + ('organisation', models.ForeignKey(on_delete=models.SET(ctrack.caf.models.EssentialService.get_sentinel_org), to='organisations.Organisation')), + ], + options={ + 'verbose_name': 'Essential Service', + }, + ), + ] diff --git a/ctrack/caf/migrations/0004_auto_20200221_2106.py b/ctrack/caf/migrations/0004_auto_20200221_2106.py new file mode 100644 index 0000000..84fa73e --- /dev/null +++ b/ctrack/caf/migrations/0004_auto_20200221_2106.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.9 on 2020-02-21 21:06 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0003_auto_20200221_2104'), + ] + + operations = [ + migrations.AlterField( + model_name='caf', + name='file', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.DocumentFile'), + ), + migrations.AlterField( + model_name='caf', + name='triage_ranking', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.Ranking'), + ), + ] diff --git a/ctrack/caf/migrations/0005_auto_20200221_2115.py b/ctrack/caf/migrations/0005_auto_20200221_2115.py new file mode 100644 index 0000000..8b94dcf --- /dev/null +++ b/ctrack/caf/migrations/0005_auto_20200221_2115.py @@ -0,0 +1,39 @@ +# Generated by Django 2.2.9 on 2020-02-21 21:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0004_auto_20200221_2106'), + ] + + operations = [ + migrations.CreateModel( + name='ConfidenceAssessment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('descriptor', models.CharField(max_length=100)), + ('description', models.TextField(max_length=250)), + ('type', models.IntegerField(choices=[(1, 'Good'), (2, 'Bad'), (3, 'OK')], default=1)), + ], + ), + migrations.AddField( + model_name='ranking', + name='description', + field=models.TextField(default='NA', max_length=250), + preserve_default=False, + ), + migrations.AlterField( + model_name='ranking', + name='type', + field=models.IntegerField(choices=[(1, 'Triage'), (2, 'First Assessment'), (3, 'Validation')], default=1), + ), + migrations.AddField( + model_name='caf', + name='confidence_assessment', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.ConfidenceAssessment'), + ), + ] diff --git a/ctrack/caf/migrations/0006_auto_20200221_2120.py b/ctrack/caf/migrations/0006_auto_20200221_2120.py new file mode 100644 index 0000000..cd1daf5 --- /dev/null +++ b/ctrack/caf/migrations/0006_auto_20200221_2120.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.9 on 2020-02-21 21:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0005_auto_20200221_2115'), + ] + + operations = [ + migrations.RemoveField( + model_name='confidenceassessment', + name='type', + ), + migrations.AlterField( + model_name='confidenceassessment', + name='descriptor', + field=models.IntegerField(choices=[(1, 'Good'), (2, 'Bad'), (3, 'OK')], default=1), + ), + ] diff --git a/ctrack/caf/migrations/0007_auto_20200221_2122.py b/ctrack/caf/migrations/0007_auto_20200221_2122.py new file mode 100644 index 0000000..a89db00 --- /dev/null +++ b/ctrack/caf/migrations/0007_auto_20200221_2122.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.9 on 2020-02-21 21:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0006_auto_20200221_2120'), + ] + + operations = [ + migrations.AlterField( + model_name='confidenceassessment', + name='descriptor', + field=models.CharField(choices=[('GOOD', 'Good'), ('BAD', 'Bad'), ('OK', 'OK')], default=1, max_length=10), + ), + ] diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py index aa70d98..5426fd9 100644 --- a/ctrack/caf/models.py +++ b/ctrack/caf/models.py @@ -14,14 +14,24 @@ from ctrack.organisations.models import Organisation class Ranking(models.Model): - RANKING_TYPE = [(1, "Triage"), (2, "First Assessment")] + RANKING_TYPE = [(1, "Triage"), (2, "First Assessment"), (3, "Validation")] descriptor = models.CharField(max_length=100) + description = models.TextField(max_length=250) type = models.IntegerField(choices=RANKING_TYPE, default=1) def __str__(self): return self.descriptor +class ConfidenceAssessment(models.Model): + RANKING_TYPE = [("GOOD", "Good"), ("BAD", "Bad"), ("OK", "OK")] + descriptor = models.CharField(max_length=10, choices=RANKING_TYPE, default=1) + description = models.TextField(max_length=250) + + def __str__(self): + return self.descriptor + + class CAFFileStore(models.Model): descriptor = models.CharField(max_length=100) virtual_location = models.CharField( @@ -45,18 +55,37 @@ class DocumentFile(models.Model): file_store_location = models.ForeignKey(CAFFileStore, on_delete=models.CASCADE) -class CAF(models.Model): - owner = models.ForeignKey(Organisation, on_delete=models.CASCADE) - # TODO: essential systems need to be tracked as entities - essential_system = models.CharField(max_length=255, blank=True) - triage_ranking = models.ForeignKey(Ranking, on_delete=models.CASCADE) - file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE, blank=True) +class EssentialService(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] + + name = models.CharField(max_length=256) + description = models.TextField(max_length=1000) + organisation = models.ForeignKey( + Organisation, on_delete=models.SET(get_sentinel_org) + ) + caf = models.ForeignKey("CAF", on_delete=models.CASCADE) + + class Meta: + verbose_name = "Essential Service" def __str__(self): - if not self.essential_system: - return f"Comprehensive CAF for {self.owner}" - else: - return f"{self.essential_system} CAF for {self.owner}" + return self.name + + +class CAF(models.Model): + owner = models.ForeignKey(Organisation, on_delete=models.CASCADE) + triage_ranking = models.ForeignKey(Ranking, on_delete=models.CASCADE, blank=True, null=True) + confidence_assessment = models.ForeignKey(ConfidenceAssessment, on_delete=models.CASCADE, blank=True, null=True) + file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE, blank=True, null=True) class Meta: verbose_name = "CAF" + + def __str__(self): + return f"CAF | {self.owner}" |