From 015b6db2f737b2d4f976745de2844f264dbd46e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sat, 11 Nov 2023 15:02:28 +0100 Subject: [PATCH] Fix detecting manual durations --- games/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/games/models.py b/games/models.py index 97462c1..620e0a0 100644 --- a/games/models.py +++ b/games/models.py @@ -151,7 +151,7 @@ class Session(models.Model): objects = SessionQuerySet.as_manager() def __str__(self): - mark = ", manual" if self.duration_manual != None else "" + mark = ", manual" if self.is_manual() else "" return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.duration_formatted()}{mark})" def finish_now(self): @@ -163,7 +163,7 @@ class Session(models.Model): def duration_seconds(self) -> timedelta: manual = timedelta(0) calculated = timedelta(0) - if not self.duration_manual in (None, 0, timedelta(0)): + if self.is_manual(): manual = self.duration_manual if self.timestamp_end != None and self.timestamp_start != None: calculated = self.timestamp_end - self.timestamp_start @@ -173,6 +173,9 @@ class Session(models.Model): result = format_duration(self.duration_seconds(), "%02.0H:%02.0m") return result + def is_manual(self) -> bool: + return not self.duration_manual == timedelta(0) + @property def duration_sum(self) -> str: return Session.objects.all().total_duration_formatted()