From cc35f276ef919334929c84fd5f9ebeb7b8c78dfe Mon Sep 17 00:00:00 2001 From: George Lacey Date: Fri, 7 May 2021 20:23:42 +0100 Subject: [PATCH] Correct references to archives --- borgweb/borg/models/repo.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/borgweb/borg/models/repo.py b/borgweb/borg/models/repo.py index 54d4127..9c026e8 100644 --- a/borgweb/borg/models/repo.py +++ b/borgweb/borg/models/repo.py @@ -12,7 +12,7 @@ class Repo(models.Model): label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True) def last_backup(self): - if self.archives.all().exists(): + if self.archive_set.all().exists(): latest = self.latest_archive().start.replace(tzinfo=None) seconds_since = int((datetime.utcnow() - latest).total_seconds()) return f"{seconds_to_string(seconds_since, False, True)} ago" @@ -20,10 +20,10 @@ class Repo(models.Model): return "No archives stored" def latest_archive(self): - return self.archives.order_by('-start')[0] + return self.archive_set.order_by('-start')[0] def size(self): - if self.archives.all().exists(): + if self.archive_set.all().exists(): cache = self.latest_archive().cache return f"{bytes_to_string(cache.unique_csize)}" else: @@ -52,20 +52,25 @@ class Repo(models.Model): if day > current_day: days.append(False) else: - cday_archives = self.archives.all().filter(start__date=cday) + cday_archives = self.archive_set.all().filter(start__date=cday) days.append(len(cday_archives) > 0) return days def get_archive_hours_dict(self): - return {"id": self.id, - "label": self.label.label, - "hours": self.get_archive_hours()} + if self.archive_set.all().exists(): + return {"id": self.id, + "label": self.label.label, + "hours": self.get_archive_hours()} + else: + return {"id": self.id, + "label": self.label.label, + "hours": []} def get_archive_hours(self): hours = [] for hour in range(24): chour = datetime.utcnow() - timedelta(hours=hour) - cday_archives = self.archives.all().filter(start__date=chour.date()).filter(start__hour=chour.hour) + cday_archives = self.archive_set.all().filter(start__date=chour.date()).filter(start__hour=chour.hour) hours.append(len(cday_archives) > 0) hours = ''.join(['H' if hour is True else '-' for hour in hours]) return hours