diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-14 16:43:17 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-14 16:43:17 +0100 |
commit | cb9f0fad4140c9cfff63f056f88da1b8bdb2f9cc (patch) | |
tree | 8d88ffe146efffe47e22d1a79ef5757621c9aa38 | |
parent | 41cf37ac30e2efac6427a4f126954a442579bc41 (diff) |
Adds basic SOP model and adds it to admin
-rw-r--r-- | engagements/utils.py | 11 | ||||
-rw-r--r-- | instruments/admin.py | 8 | ||||
-rw-r--r-- | instruments/migrations/0005_sop.py | 39 | ||||
-rw-r--r-- | instruments/migrations/0006_sop_author_lead.py | 24 | ||||
-rw-r--r-- | instruments/models.py | 27 | ||||
-rw-r--r-- | instruments/tests/test_models.py | 13 |
6 files changed, 120 insertions, 2 deletions
diff --git a/engagements/utils.py b/engagements/utils.py index b80e74d..a22595e 100644 --- a/engagements/utils.py +++ b/engagements/utils.py @@ -14,7 +14,7 @@ from engagements.models import ( RegulatoryCycle, RegulatoryRole, ) -from instruments.models import Instrument, SubInstrument +from instruments.models import SOP, Instrument, SubInstrument from myuser.models import Team, TeamUser @@ -69,6 +69,15 @@ def populate_database(): out["users"].append(u) u.save() + # SOPs + SOP.objects.create( + name="SOP 1", + designation="SOP1", + sp_link="https://example.com", + draft_status="Draft", + author_lead=u1, + ) + # RegulatoryRoles RegulatoryRole.objects.all().delete() RegulatoryRole.objects.create( diff --git a/instruments/admin.py b/instruments/admin.py index 2c55b2c..b110540 100644 --- a/instruments/admin.py +++ b/instruments/admin.py @@ -1,11 +1,17 @@ from django.contrib import admin -from .models import Instrument, SubInstrument +from .models import SOP, Instrument, SubInstrument class SubInstrumentAdmin(admin.ModelAdmin): list_display = ("__str__", "itype", "parent") +class SOPInstrumentAdmin(admin.ModelAdmin): + list_display = ("__str__", "designation", "sp_link", "draft_status", "author_lead") + ordering = ("name",) + + admin.site.register(Instrument) admin.site.register(SubInstrument, SubInstrumentAdmin) +admin.site.register(SOP, SOPInstrumentAdmin) diff --git a/instruments/migrations/0005_sop.py b/instruments/migrations/0005_sop.py new file mode 100644 index 0000000..0a6cc73 --- /dev/null +++ b/instruments/migrations/0005_sop.py @@ -0,0 +1,39 @@ +# Generated by Django 5.0.4 on 2024-10-14 15:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("instruments", "0004_alter_subinstrument_relative"), + ] + + operations = [ + migrations.CreateModel( + name="SOP", + fields=[ + ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("date_created", models.DateTimeField(auto_now_add=True)), + ("last_modified", models.DateTimeField(auto_now=True)), + ("name", models.CharField(max_length=512)), + ("designation", models.CharField(max_length=5)), + ("sp_link", models.URLField(blank=True, max_length=1000, null=True)), + ( + "draft_status", + models.CharField( + choices=[ + ("Draft", "Draft"), + ("Final", "Final"), + ("Published", "Published"), + ("To be reviewed", "To be reviewed"), + ], + max_length=20, + ), + ), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/instruments/migrations/0006_sop_author_lead.py b/instruments/migrations/0006_sop_author_lead.py new file mode 100644 index 0000000..2f2528b --- /dev/null +++ b/instruments/migrations/0006_sop_author_lead.py @@ -0,0 +1,24 @@ +# Generated by Django 5.0.4 on 2024-10-14 15:29 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("instruments", "0005_sop"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name="sop", + name="author_lead", + field=models.ForeignKey( + default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + preserve_default=False, + ), + ] diff --git a/instruments/models.py b/instruments/models.py index 9415957..3e6fa1d 100644 --- a/instruments/models.py +++ b/instruments/models.py @@ -1,6 +1,7 @@ from django.db import models from engagements.models import EngagementEffort, Organisation +from myuser.models import TeamUser class Common(models.Model): @@ -11,8 +12,33 @@ class Common(models.Model): abstract = True +class SOP(Common): + draft_status = [ + ("Draft", "Draft"), + ("Final", "Final"), + ("Published", "Published"), + ("To be reviewed", "To be reviewed"), + ] + name = models.CharField(max_length=512, null=False, blank=False) + designation = models.CharField(max_length=5, null=False, blank=False) + # sp_link is for Sharepoint so the max length has to be massive + sp_link = models.URLField(max_length=1000, null=True, blank=True) + draft_status = models.CharField(max_length=20, choices=draft_status, null=False, blank=False) + author_lead = models.ForeignKey( + TeamUser, + on_delete=models.CASCADE, + ) + + def __str__(self): + return self.name + + class Meta: + verbose_name = "SOP" + + class Instrument(Common): "JSP 628, JSP 440, the ONR ones, etc" + name = models.CharField(max_length=512, null=False, blank=False) long_title = models.CharField(max_length=1024, null=True, blank=True) designator = models.CharField(max_length=3, null=True, blank=True) @@ -28,6 +54,7 @@ class Instrument(Common): class SubInstrument(Common): "DSCs, Chapters, Supplements, Leaflets..." + choices = ( ("DSC", "Defence Security Condition (DSC)"), ("DSYAP", "Defence Security Assessment Principle (DSyAP)"), diff --git a/instruments/tests/test_models.py b/instruments/tests/test_models.py index 7762dde..4bf05f8 100644 --- a/instruments/tests/test_models.py +++ b/instruments/tests/test_models.py @@ -4,6 +4,8 @@ import pytest from engagements import models from engagements.utils import populate_database +from instruments.models import SOP +from myuser.models import TeamUser pytestmark = pytest.mark.django_db @@ -13,6 +15,17 @@ def test_data(): return populate_database() +def test_sop(): + user = TeamUser.objects.create_user(email="ming@mingy.com") + sop = SOP.objects.create( + name="SOP 1", + designation="SOP1", + sp_link="https://example.com", + draft_status="Draft", + author_lead=user, + ) + + class TestModels: def test_check_all_dcs(self, test_data): dscs = test_data.get("sub_instruments") |