Arrange into grid

This commit is contained in:
George Lacey 2021-05-10 13:04:04 +01:00
parent f2dfd2e89e
commit 62bc41692e
4 changed files with 38 additions and 24 deletions

View File

@ -1,7 +1,6 @@
from django.db import models from django.db import models
from . import Label from . import Label
from ..utility.time import time_ago from ..utility.time import time_ago
from datetime import datetime
class Error(models.Model): class Error(models.Model):

View File

@ -1,6 +1,6 @@
from django.db import models from django.db import models
from datetime import datetime, timedelta from datetime import datetime, timedelta
from ..utility.time import seconds_to_string from ..utility.time import seconds_to_string, subtract_months
from ..utility.data import bytes_to_string, convert_bytes from ..utility.data import bytes_to_string, convert_bytes
from . import Label from . import Label
@ -102,6 +102,23 @@ class Repo(models.Model):
def hourly_archive_string(self): 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(24)])
def monthly_archives(self, n_months: int = 12):
archives = []
for month in range(n_months):
current_date = subtract_months(datetime.utcnow().date(), month)
print(current_date)
archive_current_month = self.archive_set.all()\
.filter(start__year__gte=current_date.year,
start__month__gte=current_date.month,
start__year__lte=current_date.year,
start__month__lte=current_date.month)\
.order_by('-start')
if len(archive_current_month) > 0:
archives.append(archive_current_month[0])
else:
archives.append(None)
return archives
def daily_archives(self, n_days: int = 24): def daily_archives(self, n_days: int = 24):
archives = [] archives = []
for day in range(n_days): for day in range(n_days):

View File

@ -14,47 +14,46 @@
{{ hour_list|json_script:"hour_list" }} {{ hour_list|json_script:"hour_list" }}
<script src="{% static 'js/index.js' %}"></script> <script src="{% static 'js/index.js' %}"></script>
<style> <style>
.container, body, div { /*body {*/
width: 100%; /* align-content: center;*/
} /*}*/
</style> </style>
</head> </head>
<body> <body>
<p id="hours"></p>
{% if repo_list %} {% if repo_list %}
<div class="container p-3"> <div class="container p-4 d-flex align-content-center flex-wrap">
{% for repo in repo_list %} {% for repo in repo_list %}
<div class="float-lg-start rounded overflow-hidden bg-primary <div class="col-5 p-3 rounded bg-primary
{% if not repo.archive_after_latest_error %}bg-danger{% endif %}"> {% if not repo.archive_after_latest_error %}bg-danger{% endif %}">
<h2 class="repo_label">{{ repo.label }} <h2 class="py-1 e">{{ repo.label }}
<small class="text-muted"> {{ repo.location }}</small> <small class="text-muted text-truncate"> {{ repo.location }}</small>
</h2> </h2>
<dl class="row"> <dl class="row px-5 overflow-hidden">
<dt class="col-4">Latest backup:</dt> <dt class="col-3">Latest backup:</dt>
<dd class="col-8">{{ repo.last_backup }}</dd> <dd class="col-9">{{ repo.last_backup }}</dd>
</dl> </dl>
<dl class="row"> <dl class="row px-5">
<dt class="col-4">Hourly backups:</dt> <dt class="col-3">Hourly backups:</dt>
<dd class="col-8">{{ repo.hourly_archive_string }}</dd> <dd class="col-9">{{ repo.hourly_archive_string }}</dd>
</dl> </dl>
<dl class="row"> <dl class="row px-5">
<dt class="col-4">Size:</dt> <dt class="col-3">Size:</dt>
<dd class="col-8">{{ repo.size_string }}</dd> <dd class="col-9">{{ repo.size_string }}</dd>
</dl> </dl>
{% if repo.recent_errors|length > 0 %} {% if repo.recent_errors|length > 0 %}
<dl class="row"> <dl class="row">
<dt class="col-12 h4">Recent errors:</dt> <dt class="col-12 h4">Recent errors:</dt>
</dl> </dl>
{% endif %} {% endif %}
<dl class="row"> <dl class="row px-5">
{% for error in repo.recent_errors %} {% for error in repo.recent_errors %}
<dt class="col-4">{{ error.time_ago }}</dt> <dt class="col-3">{{ error.time_ago }}</dt>
<dd class="col-8 text-truncate">{{ error.error }}</dd> <dd class="col-9 text-truncate">{{ error.error }}</dd>
{% endfor %} {% endfor %}
</dl> </dl>
</div> </div>
{% endfor %} {% endfor %}
<div class="float-lg-start rounded overflow-hidden bg-primary p-3"> <div class="col-5 p-3 rounded bg-primary overflow-visible">
<canvas id="backup_csize_hourly" width="400" height="200"></canvas> <canvas id="backup_csize_hourly" width="400" height="200"></canvas>
</div> </div>
{% else %} {% else %}

View File

@ -124,7 +124,6 @@ import os
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'root') STATIC_ROOT = os.path.join(BASE_DIR, 'root')
print(os.path.join(BASE_DIR, 'bootstrap', 'dist'))
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'bootstrap', 'dist'), os.path.join(BASE_DIR, 'bootstrap', 'dist'),