Set repo background colour based on backup status

This commit is contained in:
George Lacey 2021-05-12 12:32:46 +01:00
parent 395e03803f
commit cb5ab6fdb8
2 changed files with 23 additions and 3 deletions

View File

@ -11,6 +11,26 @@ class Repo(models.Model):
last_modified = models.DateTimeField()
label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
def warning(self):
if self.error():
return True
else:
latest_archive = self.latest_archive()
if latest_archive.start > datetime.utcnow() - timedelta(hours=2):
return False
else:
return True
def error(self):
latest_archive = self.latest_archive()
if latest_archive is None or not self.archive_after_latest_error():
return True
if latest_archive.start > datetime.utcnow() - timedelta(hours=4):
return False
else:
return True
def archive_after_latest_error(self):
latest_archive = self.latest_archive()
latest_error = self.latest_error()
@ -100,7 +120,7 @@ class Repo(models.Model):
return ''.join(['H' if archive is not None else '-' for archive in archives])
def hourly_archive_string(self):
return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(24)])
return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(48)])
def monthly_archives(self, n_months: int = 12):
archives = []

View File

@ -26,8 +26,8 @@
{% if repo_list %}
<div class="grid mx-auto d-flex justify-content-center flex-wrap">
{% for repo in repo_list %}
<div style="width: 600px;" class="repo-container shadow rounded bg-primary overflow-hidden
{% if not repo.archive_after_latest_error %}bg-danger{% endif %}">
<div style="width: 600px;" class="repo-container shadow rounded overflow-hidden
{% if repo.error %}bg-danger{% elif repo.warning %}bg-warning{% else %}bg-primary{% endif %}">
<div class="row me-1 overflow-hidden text-truncate">
<h2 class="h2">{{ repo.label }}
<small class="text-muted"> {{ repo.location }}</small>