diff --git a/borgweb/borg/models/error.py b/borgweb/borg/models/error.py index 51586a1..f242e75 100644 --- a/borgweb/borg/models/error.py +++ b/borgweb/borg/models/error.py @@ -1,8 +1,14 @@ from django.db import models from . import Label +from ..utility.time import time_ago +from datetime import datetime class Error(models.Model): label = models.ForeignKey(Label, on_delete=models.CASCADE, related_name='errors') error = models.TextField() time = models.DateTimeField() + + def time_ago(self): + return f"{time_ago(self.time, False, True)} ago" + diff --git a/borgweb/borg/static/css/index.css b/borgweb/borg/static/css/index.css index 21b4ae6..5b9e1ec 100644 --- a/borgweb/borg/static/css/index.css +++ b/borgweb/borg/static/css/index.css @@ -1,7 +1,7 @@ div { padding: 8px; margin: 8px; - background: lightblue; + background: lightskyblue; } dl { diff --git a/borgweb/borg/templates/borg/index.html b/borgweb/borg/templates/borg/index.html index 01cd027..71ce2f1 100644 --- a/borgweb/borg/templates/borg/index.html +++ b/borgweb/borg/templates/borg/index.html @@ -36,9 +36,9 @@
Recent errors:
{% endif %} -
+
{% for error in repo.recent_errors %} -
{{ error.time|date:'d-m-Y H:i' }}
+
{{ error.time_ago }}
{{ error.error }}
{% endfor %}
diff --git a/borgweb/borg/utility/time.py b/borgweb/borg/utility/time.py index f901dfb..48cc887 100644 --- a/borgweb/borg/utility/time.py +++ b/borgweb/borg/utility/time.py @@ -1,3 +1,12 @@ +from datetime import datetime + + +def time_ago(time: datetime, short=False, truncate=False): + seconds = int((datetime.utcnow() - time).total_seconds()) + + return seconds_to_string(seconds, short=short, truncate=truncate) + + def seconds_to_string(seconds: int, short=False, truncate=False): seconds = int(seconds) increments = [('year', 'yr', 31557600),