diff --git a/backend/core/models.py b/backend/core/models.py index 59d8cd377..d201af8b3 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1581,12 +1581,28 @@ def get_security_objectives_display(self) -> list[dict[str, str]]: ] def get_disaster_recovery_objectives_display(self) -> list[dict[str, str]]: + def format_seconds(seconds: int) -> str: + hours, remainder = divmod(seconds, 3600) + minutes, secs = divmod(remainder, 60) + + parts = [] + if hours > 0: + parts.append(f"{hours}h") + if minutes > 0: + parts.append(f"{minutes:02d}m") + if secs > 0 or ( + not parts + ): # Always show seconds if no other parts, or if > 0 + parts.append(f"{secs:02d}s") + + return "".join(parts) + """ Gets the disaster recovery objectives of a given asset as strings. """ disaster_recovery_objectives = self.get_disaster_recovery_objectives() return [ - {"str": f"{key}: {content.get('value', 0)}"} + {"str": f"{key}: {format_seconds(content.get('value', 0))}"} for key, content in disaster_recovery_objectives.get( "objectives", {} ).items()