Correct references to archives
This commit is contained in:
parent
5c6f05256a
commit
cc35f276ef
|
@ -12,7 +12,7 @@ class Repo(models.Model):
|
||||||
label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
|
label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
|
||||||
|
|
||||||
def last_backup(self):
|
def last_backup(self):
|
||||||
if self.archives.all().exists():
|
if self.archive_set.all().exists():
|
||||||
latest = self.latest_archive().start.replace(tzinfo=None)
|
latest = self.latest_archive().start.replace(tzinfo=None)
|
||||||
seconds_since = int((datetime.utcnow() - latest).total_seconds())
|
seconds_since = int((datetime.utcnow() - latest).total_seconds())
|
||||||
return f"{seconds_to_string(seconds_since, False, True)} ago"
|
return f"{seconds_to_string(seconds_since, False, True)} ago"
|
||||||
|
@ -20,10 +20,10 @@ class Repo(models.Model):
|
||||||
return "No archives stored"
|
return "No archives stored"
|
||||||
|
|
||||||
def latest_archive(self):
|
def latest_archive(self):
|
||||||
return self.archives.order_by('-start')[0]
|
return self.archive_set.order_by('-start')[0]
|
||||||
|
|
||||||
def size(self):
|
def size(self):
|
||||||
if self.archives.all().exists():
|
if self.archive_set.all().exists():
|
||||||
cache = self.latest_archive().cache
|
cache = self.latest_archive().cache
|
||||||
return f"{bytes_to_string(cache.unique_csize)}"
|
return f"{bytes_to_string(cache.unique_csize)}"
|
||||||
else:
|
else:
|
||||||
|
@ -52,20 +52,25 @@ class Repo(models.Model):
|
||||||
if day > current_day:
|
if day > current_day:
|
||||||
days.append(False)
|
days.append(False)
|
||||||
else:
|
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)
|
days.append(len(cday_archives) > 0)
|
||||||
return days
|
return days
|
||||||
|
|
||||||
def get_archive_hours_dict(self):
|
def get_archive_hours_dict(self):
|
||||||
return {"id": self.id,
|
if self.archive_set.all().exists():
|
||||||
"label": self.label.label,
|
return {"id": self.id,
|
||||||
"hours": self.get_archive_hours()}
|
"label": self.label.label,
|
||||||
|
"hours": self.get_archive_hours()}
|
||||||
|
else:
|
||||||
|
return {"id": self.id,
|
||||||
|
"label": self.label.label,
|
||||||
|
"hours": []}
|
||||||
|
|
||||||
def get_archive_hours(self):
|
def get_archive_hours(self):
|
||||||
hours = []
|
hours = []
|
||||||
for hour in range(24):
|
for hour in range(24):
|
||||||
chour = datetime.utcnow() - timedelta(hours=hour)
|
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.append(len(cday_archives) > 0)
|
||||||
hours = ''.join(['H' if hour is True else '-' for hour in hours])
|
hours = ''.join(['H' if hour is True else '-' for hour in hours])
|
||||||
return hours
|
return hours
|
||||||
|
|
Loading…
Reference in New Issue
Block a user