diff options
author | Yulqen <246857+yulqen@users.noreply.github.com> | 2024-09-10 15:58:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-10 15:58:55 +0100 |
commit | dcfe6d87098bbe064d2db268f0972865c3d412bf (patch) | |
tree | 2b82df07a5290f80f25e9780596cbce0f128454f /engagements/models.py | |
parent | 7ddc22b821f405546786977225e7b194a19b2b77 (diff) | |
parent | 15b2dc965bfe2271d73476fcf9ff636c60113908 (diff) |
Merge pull request #106 from defencedigital/postgres-migration
Adds new Engagement Strategy stuff
Diffstat (limited to 'engagements/models.py')
-rw-r--r-- | engagements/models.py | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/engagements/models.py b/engagements/models.py index 20bed8d..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) @@ -27,6 +29,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) @@ -154,6 +157,9 @@ class Engagement(Common): "L4RIF": "L4 RIF", } + def get_officers(self): + return [" ".join([x.first_name, x.last_name]) for x in self.officers.all()] + def total_planning_effort(self): p_effort = self.engagementeffort_set.all().filter(is_planned=True) return sum([x.effort_total_hours() for x in p_effort]) @@ -173,7 +179,7 @@ class Engagement(Common): def dscs(self): "Return all declared DSCs as part of REGULATION effort" dscs = set() - for ee in EngagementEffort.objects.filter(engagement=self, effort_type="REGULATION"): + for ee in EngagementEffort.objects.filter(engagement=self): for si in ee.sub_instruments.all(): dscs.add(si) return dscs @@ -191,7 +197,7 @@ class EngagementEffort(Common): ("PLANNING", "Planning"), ("REGULATION", "Regulation (On-site or Remote)"), ("DISCUSSION", "Discussion"), - ("REPORT", "Reporting"), + ("REPORTING", "Reporting"), ) is_planned = models.BooleanField(null=True, blank=True, verbose_name="Planned", default=True) effort_type = models.CharField(max_length=32, choices=choices, verbose_name="Effort Type") @@ -206,6 +212,9 @@ class EngagementEffort(Common): verbose_name_plural = "Engagement Effort" ordering = ("proposed_start_date",) + def get_officers(self): + return [" ".join([x.first_name, x.last_name]) for x in self.officers.all()] + def effort_total_hours(self): "Returns total effort for this engagement." delta = self.proposed_end_date - self.proposed_start_date @@ -234,3 +243,55 @@ 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): + STATUS = ( + ("DRAFT", "Draft"), + ("SUBMITTED", "Submitted"), + ("APPROVED", "Approved"), + ("REJECTED", "Rejected"), + ) + + 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, 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" |