From 6c8b6a2a19f25eaac84e15f59c082b91ef123534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 14 Apr 2021 16:29:28 +0300 Subject: [PATCH] Remove functools.cached_property usage Cannot use functools.cached_property, as it was added in Py 3.8, but we support 3.6+ --- hc/accounts/models.py | 23 +++++++++++------------ hc/front/views.py | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 1dde19a0..cf84abf9 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -1,5 +1,4 @@ from datetime import timedelta -from functools import cached_property from secrets import token_urlsafe from urllib.parse import quote, urlencode import uuid @@ -343,18 +342,18 @@ class Project(models.Model): for profile in q: profile.update_next_nag_date() - @cached_property def overall_status(self): - status = "up" - for check in self.check_set.all(): - check_status = check.get_status() - if status == "up" and check_status == "grace": - status = "grace" - - if check_status == "down": - status = "down" - break - return status + if not hasattr(self, "_overall_status"): + self._overall_status = "up" + for check in self.check_set.all(): + check_status = check.get_status() + if check_status == "grace" and self._overall_status == "up": + self._overall_status = "grace" + elif check_status == "down": + self._overall_status = "down" + break + + return self._overall_status def get_n_down(self): result = 0 diff --git a/hc/front/views.py b/hc/front/views.py index a0163d4c..5fc1e54a 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -285,7 +285,7 @@ def index(request): projects = list(q) # Primary sort key: projects with overall_status=down go first # Secondary sort key: project's name - projects.sort(key=lambda p: (p.overall_status != "down", p.name)) + projects.sort(key=lambda p: (p.overall_status() != "down", p.name)) ctx = { "page": "projects",