diff options
-rw-r--r-- | engagements/admin.py | 6 | ||||
-rw-r--r-- | engagements/migrations/0006_engagementstrategy_owned_by_and_more.py | 38 | ||||
-rw-r--r-- | engagements/migrations/0007_alter_engagementstrategy_reviewed_by.py | 27 | ||||
-rw-r--r-- | engagements/migrations/0008_alter_engagementstrategy_options_and_more.py | 21 | ||||
-rw-r--r-- | engagements/migrations/0009_alter_engagementstrategy_description.py | 18 | ||||
-rw-r--r-- | engagements/migrations/0010_remove_engagementstrategy_name.py | 17 | ||||
-rw-r--r-- | engagements/models.py | 28 | ||||
-rw-r--r-- | engagements/tests/conftest.py | 5 | ||||
-rw-r--r-- | engagements/tests/test_models.py | 6 |
9 files changed, 160 insertions, 6 deletions
diff --git a/engagements/admin.py b/engagements/admin.py index 5c582ee..3b9d05c 100644 --- a/engagements/admin.py +++ b/engagements/admin.py @@ -4,6 +4,7 @@ from .models import ( Engagement, EngagementEffort, EngagementType, + EngagementStrategy, Organisation, Person, RegulatedEntityType, @@ -16,6 +17,10 @@ site = admin.site site.site_header = "DefNucSyR Engagement Database (DED)" +class EngagementStrategyAdmin(admin.ModelAdmin): + list_display = ("__str__", "owned_by") + + class PersonAdmin(admin.ModelAdmin): list_display = ("__str__", "organisation") @@ -39,5 +44,6 @@ site.register(RegulatedEntityType) site.register(RegulatoryRole) site.register(RegulatoryCycle, RegulatoryCycleAdmin) site.register(EngagementType) +site.register(EngagementStrategy, EngagementStrategyAdmin) site.register(Engagement) site.register(EngagementEffort) diff --git a/engagements/migrations/0006_engagementstrategy_owned_by_and_more.py b/engagements/migrations/0006_engagementstrategy_owned_by_and_more.py new file mode 100644 index 0000000..8b0a509 --- /dev/null +++ b/engagements/migrations/0006_engagementstrategy_owned_by_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 5.0.4 on 2024-09-10 12:33 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("engagements", "0005_engagementstrategy"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name="engagementstrategy", + name="owned_by", + field=models.ForeignKey( + default=1, + on_delete=django.db.models.deletion.CASCADE, + related_name="owned_engagement_strategies", + to=settings.AUTH_USER_MODEL, + ), + preserve_default=False, + ), + migrations.AddField( + model_name="engagementstrategy", + name="reviewed_by", + field=models.ForeignKey( + default=1, + on_delete=django.db.models.deletion.CASCADE, + related_name="reviewed_engagement_strategies", + to=settings.AUTH_USER_MODEL, + ), + preserve_default=False, + ), + ] diff --git a/engagements/migrations/0007_alter_engagementstrategy_reviewed_by.py b/engagements/migrations/0007_alter_engagementstrategy_reviewed_by.py new file mode 100644 index 0000000..cacae95 --- /dev/null +++ b/engagements/migrations/0007_alter_engagementstrategy_reviewed_by.py @@ -0,0 +1,27 @@ +# Generated by Django 5.0.4 on 2024-09-10 12:45 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("engagements", "0006_engagementstrategy_owned_by_and_more"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AlterField( + model_name="engagementstrategy", + name="reviewed_by", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="reviewed_engagement_strategies", + to=settings.AUTH_USER_MODEL, + ), + ), + ] diff --git a/engagements/migrations/0008_alter_engagementstrategy_options_and_more.py b/engagements/migrations/0008_alter_engagementstrategy_options_and_more.py new file mode 100644 index 0000000..c9b7a50 --- /dev/null +++ b/engagements/migrations/0008_alter_engagementstrategy_options_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 5.0.4 on 2024-09-10 12:49 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("engagements", "0007_alter_engagementstrategy_reviewed_by"), + ] + + operations = [ + migrations.AlterModelOptions( + name="engagementstrategy", + options={"ordering": ("start_year",), "verbose_name_plural": "Engagement Strategies"}, + ), + migrations.AlterUniqueTogether( + name="engagementstrategy", + unique_together={("start_year", "organisation")}, + ), + ] diff --git a/engagements/migrations/0009_alter_engagementstrategy_description.py b/engagements/migrations/0009_alter_engagementstrategy_description.py new file mode 100644 index 0000000..8fc9511 --- /dev/null +++ b/engagements/migrations/0009_alter_engagementstrategy_description.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-09-10 12:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("engagements", "0008_alter_engagementstrategy_options_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="engagementstrategy", + name="description", + field=models.TextField(blank=True, max_length=1024, null=True), + ), + ] diff --git a/engagements/migrations/0010_remove_engagementstrategy_name.py b/engagements/migrations/0010_remove_engagementstrategy_name.py new file mode 100644 index 0000000..45aa795 --- /dev/null +++ b/engagements/migrations/0010_remove_engagementstrategy_name.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.4 on 2024-09-10 13:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("engagements", "0009_alter_engagementstrategy_description"), + ] + + operations = [ + migrations.RemoveField( + model_name="engagementstrategy", + name="name", + ), + ] diff --git a/engagements/models.py b/engagements/models.py index 8876d91..45d8e69 100644 --- a/engagements/models.py +++ b/engagements/models.py @@ -5,6 +5,8 @@ from django.utils.text import slugify from myuser.models import TeamUser +ES_YEAR_LENGTH = 3 + class Common(models.Model): date_created = models.DateTimeField(auto_now_add=True) @@ -263,11 +265,33 @@ class EngagementStrategy(Common): ("REJECTED", "Rejected"), ) - name = models.CharField(max_length=128, null=False, blank=False) organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE) start_year = models.ForeignKey(RegulatoryCycle, on_delete=models.CASCADE, related_name="start_year") end_year = models.ForeignKey(RegulatoryCycle, on_delete=models.CASCADE, related_name="end_year") - description = models.TextField(max_length=1024) + description = models.TextField(max_length=1024, null=True, blank=True) inspector_sign_off = models.DateField(null=True, blank=True) + owned_by = models.ForeignKey( + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="owned_engagement_strategies" + ) + reviewed_by = models.ForeignKey( + settings.AUTH_USER_MODEL, + null=True, + blank=True, + on_delete=models.CASCADE, + related_name="reviewed_engagement_strategies", + ) management_sign_off = models.DateField(null=True, blank=True) status = models.CharField(max_length=32, choices=STATUS, default=STATUS[0][0]) + + def get_end_year(self) -> int: + return self.start_year.start_date.year + (ES_YEAR_LENGTH - 1) + + def __str__(self): + return ( + f"Engagement Strategy ({self.start_year.start_date.year}-{self.get_end_year()}) - {self.organisation.name}" + ) + + class Meta: + ordering = ("start_year",) + unique_together = ("start_year", "organisation") + verbose_name_plural = "Engagement Strategies" diff --git a/engagements/tests/conftest.py b/engagements/tests/conftest.py index b74feb5..7ccb9ad 100644 --- a/engagements/tests/conftest.py +++ b/engagements/tests/conftest.py @@ -19,13 +19,14 @@ def org(): @pytest.fixture -def engagement_strategy(regulatory_cycles, org): +def engagement_strategy(regulatory_cycles, org, user): es = EngagementStrategy.objects.create( - name="ES1", description="ES1 description", start_year=RegulatoryCycle.objects.get(start_date="2022-01-01"), end_year=RegulatoryCycle.objects.get(start_date="2024-01-01"), organisation=org, + owned_by=user, + reviewed_by=user, management_sign_off="2022-02-10", inspector_sign_off="2022-01-10", status="DRAFT", diff --git a/engagements/tests/test_models.py b/engagements/tests/test_models.py index 426d728..70ae31a 100644 --- a/engagements/tests/test_models.py +++ b/engagements/tests/test_models.py @@ -1,7 +1,7 @@ import pytest +from engagements.models import EngagementStrategy, RegulatoryCycle from engagements.utils import populate_database -from engagements.models import RegulatoryCycle, EngagementStrategy pytestmark = pytest.mark.django_db @@ -40,4 +40,6 @@ def test_regulatory_cycle_model(regulatory_cycles): def test_engagement_strategy_model(engagement_strategy): - assert EngagementStrategy.objects.first() + es1 = EngagementStrategy.objects.first() + assert es1.organisation.name == "MOD" + assert str(es1) == "Engagement Strategy (2022-2024) - MOD" |