from django.db import models from engagements.models import EngagementEffort, Organisation from myuser.models import TeamUser class Common(models.Model): date_created = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) class Meta: 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) owner = models.ForeignKey(Organisation, null=False, blank=False, on_delete=models.CASCADE) link = models.URLField(max_length=1024, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name_plural = "Instruments" class SubInstrument(Common): "DSCs, Chapters, Supplements, Leaflets..." choices = ( ("DSC", "Defence Security Condition (DSC)"), ("DSYAP", "Defence Security Assessment Principle (DSyAP)"), ("DSTAIG", "Defence Security Testing And I Don't Know (DSTAIG)"), ) is_guidance = models.BooleanField(null=True, blank=True, default=False) itype = models.CharField(choices=choices, max_length=6, verbose_name="Instrument Type") title = models.CharField(max_length=512, null=False, blank=False) parent = models.ForeignKey(Instrument, on_delete=models.CASCADE, verbose_name="Parent Instrument") description = models.TextField(null=True, blank=True) rationale = models.TextField(null=True, blank=True) relative = models.ManyToManyField("self", blank=True) short = models.CharField(max_length=10, null=True, blank=True) def effort(self): return EngagementEffort.objects.filter(sub_instruments__contains=self) def effort_for_org(self, org): eff = EngagementEffort.objects.filter(engagement__external_party=org).filter(effort_type="REGULATION") return sum(e.effort_total_hours() for e in eff) def __str__(self): return self.title class Meta: verbose_name_plural = "Sub Instruments"