From bc6ccd55b33a1856fc07f0b1cf1c51494c56bfec Mon Sep 17 00:00:00 2001 From: James Kirsop Date: Fri, 27 Mar 2020 14:19:57 +1100 Subject: [PATCH] Implementation of history using Flips model statuses for a check --- hc/api/models.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/hc/api/models.py b/hc/api/models.py index 8e9ccf64..5271d911 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -237,16 +237,11 @@ class Check(models.Model): elif split[1] == 'w': cutoff = current_now - td(weeks=int(split[0])) - pings = Ping.objects.filter(owner=self, created__gte=cutoff).order_by("-id")#[:limit] - pings = list(pings) - - alerts = Notification.objects.select_related("channel").filter( - owner=self, check_status="down", created__gt=cutoff - ) - - events = pings + list(alerts) - events.sort(key=lambda el: el.created, reverse=True) - result['history'] = list(map(lambda x: {'timestamp':x.created,'status':x.kind}, events)) + flips = Flip.objects.select_related("owner").filter( + owner=self, new_status__in=("down","up"), created__gt=cutoff + ).order_by("created") + dictStatus = {"up":1,"down":0} + result['history'] = list(map(lambda x: {'timestamp':x.created,'status':dictStatus[x.new_status]}, flips)) if readonly: result["unique_key"] = self.unique_key else: