Correct references to archives

This commit is contained in:
George Lacey 2021-05-07 20:23:42 +01:00
parent 5c6f05256a
commit cc35f276ef

View File

@ -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):
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