diff --git a/borgweb/borg/models/repo.py b/borgweb/borg/models/repo.py index ff97d9c..94ad1f7 100644 --- a/borgweb/borg/models/repo.py +++ b/borgweb/borg/models/repo.py @@ -11,6 +11,16 @@ class Repo(models.Model): last_modified = models.DateTimeField() label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True) + def archive_after_latest_error(self): + latest_archive = self.latest_archive() + latest_error = self.latest_error() + if latest_archive is None: + return False + elif latest_error is None: + return True + else: + return latest_archive.start > latest_error.time + def last_backup(self): if self.archive_set.all().exists(): latest = self.latest_archive().start.replace(tzinfo=None) @@ -20,7 +30,18 @@ class Repo(models.Model): return "No archives stored" def latest_archive(self): - return self.archive_set.order_by('-start')[0] + archives = self.archive_set.order_by('-start') + if len(archives) > 0: + return archives[0] + else: + return None + + def latest_error(self): + errors = self.label.errors.all().order_by('-time') + if len(errors) > 0: + return errors[0] + else: + return None def size(self): if self.archive_set.all().exists(): @@ -35,9 +56,6 @@ class Repo(models.Model): errors = self.label.errors.all().filter(time__gt=days_ago) return errors - def archive_dates(self): - days = self.get_archive_days() - def get_archive_days(self): current_day = datetime.utcnow().day days = [] diff --git a/borgweb/borg/static/css/index.css b/borgweb/borg/static/css/index.css index 5b9e1ec..7774c24 100644 --- a/borgweb/borg/static/css/index.css +++ b/borgweb/borg/static/css/index.css @@ -1,7 +1,6 @@ div { padding: 8px; margin: 8px; - background: lightskyblue; } dl { diff --git a/borgweb/borg/static/js/index.js b/borgweb/borg/static/js/index.js index 455756b..a329642 100644 --- a/borgweb/borg/static/js/index.js +++ b/borgweb/borg/static/js/index.js @@ -1,7 +1,7 @@ +window.addEventListener("DOMContentLoaded", function () { -window.addEventListener("DOMContentLoaded", function() { - const hour_json = JSON.parse(document.getElementById('hour_list').textContent); - hour_json.forEach(function(repo) { - console.log(repo.hours); - }) - }, false); \ No newline at end of file + const hour_json = JSON.parse(document.getElementById('hour_list').textContent); + hour_json.forEach(function (repo) { + console.log(repo.hours); + }) +}, false); \ No newline at end of file diff --git a/borgweb/borg/templates/borg/index.html b/borgweb/borg/templates/borg/index.html index 71ce2f1..24b0658 100644 --- a/borgweb/borg/templates/borg/index.html +++ b/borgweb/borg/templates/borg/index.html @@ -4,20 +4,26 @@ Borg Summary + {% load static %} + - {{ hour_list|json_script:"hour_list" }} +

{% if repo_list %} {% for repo in repo_list %} -
+ {% if repo.archive_after_latest_error %} +
+ {% else %} +
+ {% endif %}

{{ repo.label }} {{ repo.location }}

Latest backup:
@@ -44,9 +50,11 @@
{% endfor %} - {% else %}

No repos found.

{% endif %} +
+ +
\ No newline at end of file