summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--engagements/admin.py11
-rw-r--r--engagements/migrations/0004_regulatorycycle_alter_engagementeffort_effort_type.py42
-rw-r--r--engagements/models.py21
-rw-r--r--engagements/tests/conftest.py11
-rw-r--r--engagements/tests/test_models.py12
-rw-r--r--engagements/utils.py6
6 files changed, 102 insertions, 1 deletions
diff --git a/engagements/admin.py b/engagements/admin.py
index 9861867..5c582ee 100644
--- a/engagements/admin.py
+++ b/engagements/admin.py
@@ -7,6 +7,7 @@ from .models import (
Organisation,
Person,
RegulatedEntityType,
+ RegulatoryCycle,
RegulatoryRole,
)
@@ -23,10 +24,20 @@ class PersonAdmin(admin.ModelAdmin):
return f"{obj.first_name} {obj.last_name}"
+class RegulatoryCycleAdmin(admin.ModelAdmin):
+ @admin.display(description="year")
+ def year(self, obj):
+ return f"{obj.get_year()}"
+
+ list_display = ("__str__", "year")
+ ordering = ("-start_date",)
+
+
site.register(Person, PersonAdmin)
site.register(Organisation)
site.register(RegulatedEntityType)
site.register(RegulatoryRole)
+site.register(RegulatoryCycle, RegulatoryCycleAdmin)
site.register(EngagementType)
site.register(Engagement)
site.register(EngagementEffort)
diff --git a/engagements/migrations/0004_regulatorycycle_alter_engagementeffort_effort_type.py b/engagements/migrations/0004_regulatorycycle_alter_engagementeffort_effort_type.py
new file mode 100644
index 0000000..00d9db6
--- /dev/null
+++ b/engagements/migrations/0004_regulatorycycle_alter_engagementeffort_effort_type.py
@@ -0,0 +1,42 @@
+# Generated by Django 5.0.4 on 2024-09-10 10:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("engagements", "0003_engagementeffort_notes"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="RegulatoryCycle",
+ 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)),
+ ("start_date", models.DateField()),
+ ("end_date", models.DateField()),
+ ("description", models.TextField(blank=True, max_length=1024, null=True)),
+ ],
+ options={
+ "abstract": False,
+ },
+ ),
+ migrations.AlterField(
+ model_name="engagementeffort",
+ name="effort_type",
+ field=models.CharField(
+ choices=[
+ ("TRAVEL", "Travel"),
+ ("PLANNING", "Planning"),
+ ("REGULATION", "Regulation (On-site or Remote)"),
+ ("DISCUSSION", "Discussion"),
+ ("REPORTING", "Reporting"),
+ ],
+ max_length=32,
+ verbose_name="Effort Type",
+ ),
+ ),
+ ]
diff --git a/engagements/models.py b/engagements/models.py
index b0dfe2b..ef0aee3 100644
--- a/engagements/models.py
+++ b/engagements/models.py
@@ -27,6 +27,7 @@ class RegulatoryRole(Common):
class Person(Common):
"External person, rather than MOD at this point."
+
first_name = models.CharField(max_length=64, null=False, blank=False)
last_name = models.CharField(max_length=64, null=False, blank=False)
organisation = models.ForeignKey("Organisation", null=False, blank=False, on_delete=models.CASCADE)
@@ -240,3 +241,23 @@ class EngagementEffort(Common):
def __str__(self):
return f"{self.effort_type} effort for {self.engagement}: {self.proposed_end_date - self.proposed_start_date}"
+
+
+class RegulatoryCycle(Common):
+ start_date = models.DateField(null=False, blank=False)
+ end_date = models.DateField(null=False, blank=False)
+ description = models.TextField(max_length=1024, null=True, blank=True)
+
+ def get_year(self):
+ return str(self.start_date.year)
+
+ def __str__(self):
+ return f"Regulatory Cycle: {self.get_year()}"
+
+
+# class EngagementStrategy(Common):
+# name = models.CharField(max_length=128, null=False, blank=False)
+# start_date = models.DateField(null=False, blank=False)
+# end_date
+# description = models.TextField(max_length=1024)
+# engagement = models.ForeignKey(Engagement, on_delete=models.CASCADE)
diff --git a/engagements/tests/conftest.py b/engagements/tests/conftest.py
index cb0b9e0..72f1c11 100644
--- a/engagements/tests/conftest.py
+++ b/engagements/tests/conftest.py
@@ -1,10 +1,19 @@
import pytest
-from engagements.models import EngagementType, Organisation, Engagement
+from datetime import date
+
+from engagements.models import EngagementType, Organisation, Engagement, RegulatoryCycle
from myuser.models import TeamUser
@pytest.fixture
+def regulatory_cycles():
+ RegulatoryCycle.objects.create(start_date="2024-01-01", end_date="2024-12-31")
+ RegulatoryCycle.objects.create(start_date="2023-01-01", end_date="2023-12-31")
+ RegulatoryCycle.objects.create(start_date="2022-01-01", end_date="2022-12-31")
+
+
+@pytest.fixture
def engagement():
data = {
"proposed_start_date": "2022-10-01",
diff --git a/engagements/tests/test_models.py b/engagements/tests/test_models.py
index 3b84ead..d7aa458 100644
--- a/engagements/tests/test_models.py
+++ b/engagements/tests/test_models.py
@@ -1,6 +1,7 @@
import pytest
from engagements.utils import populate_database
+from engagements.models import RegulatoryCycle
pytestmark = pytest.mark.django_db
@@ -29,3 +30,14 @@ def test_effort_by_type(data):
def test_total_effort_for_engagement(data):
e = data["engagements"][0]
assert e.total_effort() == 5.25
+
+
+def test_regulatory_cycle_model(regulatory_cycles):
+ rc = RegulatoryCycle.objects.first()
+ rc2023 = RegulatoryCycle.objects.get(start_date="2023-01-01")
+ assert str(rc) == "Regulatory Cycle: 2024"
+ assert str(rc2023) == "Regulatory Cycle: 2023"
+
+
+# def test_engagement_strategy_model(data):
+# assert EngagementStrategy.objects.first()
diff --git a/engagements/utils.py b/engagements/utils.py
index 2c4ff72..3b414e9 100644
--- a/engagements/utils.py
+++ b/engagements/utils.py
@@ -11,6 +11,7 @@ from engagements.models import (
Organisation,
Person,
RegulatedEntityType,
+ RegulatoryCycle,
RegulatoryRole,
)
from instruments.models import Instrument, SubInstrument
@@ -88,6 +89,11 @@ def populate_database():
designator="JSP628",
owner=o1,
)
+ # Some Regulatory Cycles
+ RegulatoryCycle.objects.create(start_date="2022-01-01", end_date="2022-12-31")
+ RegulatoryCycle.objects.create(start_date="2023-01-01", end_date="2023-12-31")
+ RegulatoryCycle.objects.create(start_date="2024-01-01", end_date="2024-12-31")
+
# Create the DSCs
Faker.seed(0)
SubInstrument.objects.all().delete()