Coverage for backend/django/core/auxiliary/models/MonitoringTable.py: 94%

33 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-02-12 01:47 +0000

1from django.db import models 

2from core.managers import AccessControlManager 

3 

4 

5class MonitoringTable(models.Model): 

6 """ 

7 This model represents a monitoring table, which is a table that displays the values of  

8 chosen properties. 

9 """ 

10 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="monitoringTables") 

11 group = models.ForeignKey("flowsheetInternals_graphicData.Grouping", on_delete=models.CASCADE, related_name="monitoringTables") 

12 properties = models.ManyToManyField("core_auxiliary.PropertyInfo", through="core_auxiliary.MonitoringTableProperty", related_name="monitoringTables", blank=True) 

13 title = models.CharField(max_length=255) 

14 x = models.FloatField(default=440) 

15 y = models.FloatField(default=110) 

16 width = models.FloatField(default=380) 

17 height = models.FloatField(default=100) 

18 minimised = models.BooleanField(default=True) 

19 visible = models.BooleanField(default=False) 

20 

21 created_at = models.DateTimeField(auto_now_add=True) 

22 objects = AccessControlManager() 

23 

24 

25 

26class MonitoringTableProperty(models.Model): 

27 """ 

28 Selected property row for a monitoring table. 

29 Stores ordering and explicit links to simulation object + property info. 

30 """ 

31 

32 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="monitoringTableProperties", null=True, blank=True) 

33 table = models.ForeignKey("core_auxiliary.MonitoringTable", on_delete=models.CASCADE, related_name="selectedProperties") 

34 simulationObject = models.ForeignKey("flowsheetInternals_unitops.SimulationObject", on_delete=models.CASCADE, related_name="monitoringTableProperties") 

35 propertyInfo = models.ForeignKey("core_auxiliary.PropertyInfo", on_delete=models.CASCADE, related_name="monitoringTableProperties") 

36 sortIndex = models.PositiveIntegerField(default=0) # index for ordering properties within the table 

37 

38 created_at = models.DateTimeField(auto_now_add=True) 

39 objects = AccessControlManager() 

40 

41 def save(self, *args, **kwargs): 

42 # ensure flowsheet is populated from the parent table when possible 

43 if not self.flowsheet and getattr(self, "table_id", None): 

44 try: 

45 self.flowsheet = self.table.flowsheet 

46 except Exception: 

47 pass 

48 super().save(*args, **kwargs) 

49 

50 class Meta: 

51 ordering = ["sortIndex", "created_at"] 

52 constraints = [ 

53 models.UniqueConstraint( 

54 fields=["table", "simulationObject", "propertyInfo"], 

55 name="unique_monitoring_table_property", 

56 ) 

57 ] 

58 

59