Remove functools.cached_property usage

Cannot use functools.cached_property, as it was added in Py 3.8,
but we support 3.6+
This commit is contained in:
Pēteris Caune 2021-04-14 16:29:28 +03:00
parent 738a648407
commit 6c8b6a2a19
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
2 changed files with 11 additions and 12 deletions

View File

@ -1,5 +1,4 @@
from datetime import timedelta from datetime import timedelta
from functools import cached_property
from secrets import token_urlsafe from secrets import token_urlsafe
from urllib.parse import quote, urlencode from urllib.parse import quote, urlencode
import uuid import uuid
@ -343,18 +342,18 @@ class Project(models.Model):
for profile in q: for profile in q:
profile.update_next_nag_date() profile.update_next_nag_date()
@cached_property
def overall_status(self): def overall_status(self):
status = "up" if not hasattr(self, "_overall_status"):
self._overall_status = "up"
for check in self.check_set.all(): for check in self.check_set.all():
check_status = check.get_status() check_status = check.get_status()
if status == "up" and check_status == "grace": if check_status == "grace" and self._overall_status == "up":
status = "grace" self._overall_status = "grace"
elif check_status == "down":
if check_status == "down": self._overall_status = "down"
status = "down"
break break
return status
return self._overall_status
def get_n_down(self): def get_n_down(self):
result = 0 result = 0

View File

@ -285,7 +285,7 @@ def index(request):
projects = list(q) projects = list(q)
# Primary sort key: projects with overall_status=down go first # Primary sort key: projects with overall_status=down go first
# Secondary sort key: project's name # 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 = { ctx = {
"page": "projects", "page": "projects",