Show basic repo information

This commit is contained in:
George Lacey 2021-05-07 14:04:22 +01:00
parent bd31338b9e
commit feb1953064
5 changed files with 80 additions and 23 deletions

View File

@ -22,9 +22,7 @@ class Repo(models.Model):
def size(self): def size(self):
cache = self.latest_archive().cache cache = self.latest_archive().cache
size = bytes_to_string(cache.unique_size) return f"{bytes_to_string(cache.unique_csize)}"
csize = bytes_to_string(cache.unique_csize)
return f"{size}/{csize}"
def recent_errors(self): def recent_errors(self):
days = 7 days = 7
@ -34,3 +32,35 @@ class Repo(models.Model):
return f"1 error since {days} days ago" return f"1 error since {days} days ago"
else: else:
return f"{len(errors)} errors since {days} days ago" return f"{len(errors)} errors since {days} days ago"
def archive_dates(self):
days = self.get_archive_days()
def get_archive_days(self):
current_day = datetime.utcnow().day
days = []
for day in reversed(range(1, 31)):
try:
cday = datetime.utcnow().replace(day=day)
except ValueError:
continue
if day > current_day:
days.append(False)
else:
cday_archives = self.archives.all().filter(start__date=cday)
days.append(len(cday_archives) > 0)
return days
def get_archive_hours_dict(self):
return {"id": self.id,
"label": self.label.label,
"hours": self.get_archive_hours()}
def get_archive_hours(self):
hours = []
for hour in range(24):
chour = datetime.utcnow() - timedelta(hours=hour)
cday_archives = self.archives.all().filter(start__date=chour.date()).filter(start__hour=chour.hour)
hours.append(len(cday_archives) > 0)
hours = ''.join(['H' if hour is True else '-' for hour in hours])
return hours

View File

@ -0,0 +1,19 @@
.repo_info {
outline: 2px solid black;
padding: 8px;
float: left;
width: auto;
margin: 16px;
}
.repo_label {
font-size: x-large;
}
.repo_point {
list-style-type: none;
}
.point_label {
font-weight: bold;
}

View File

@ -0,0 +1,7 @@
window.addEventListener("DOMContentLoaded", function() {
const hour_json = JSON.parse(document.getElementById('hour_list').textContent);
hour_json.forEach(function(repo) {
console.log(repo.hours);
})
}, false);

View File

@ -2,24 +2,29 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Borg Summary</title>
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}">
{{ hour_list|json_script:"hour_list" }}
<script src="{% static 'js/index.js' %}"></script>
</head>
<body>
<p id="hours"></p>
{% if repo_list %} {% if repo_list %}
{% for repo in repo_list %} {% for repo in repo_list %}
<div> <div class="repo_info">
<header>{{ repo.label }} ({{ repo.location }}) </header> <header class="repo_label">{{ repo.label }} ({{ repo.location }}) </header>
<ul> <ul class="repo_details">
<li>Latest backup: {{ repo.last_backup }}</li> <li class="repo_point"><span class="point_label">Latest backup:</span> {{ repo.last_backup }}</li>
<li>Un/Compressed size: {{ repo.size }}</li> <li class="repo_point"><span class="point_label">Hourly backups:</span> {{ repo.get_archive_hours }}</li>
<li>{{ repo.recent_errors }}</li> <li class="repo_point"><span class="point_label">Size:</span> {{ repo.size }}</li>
<li class="repo_point"><span class="point_label">{{ repo.recent_errors }}</span></li>
</ul> </ul>
</div> </div>
{% endfor %} {% endfor %}
<canvas id="daily_backup_graphic" width="200" height="100"></canvas>
{% else %} {% else %}
<p>No repos found.</p> <p>No repos found.</p>
{% endif %} {% endif %}
</head>
<body>
</body> </body>
</html> </html>

View File

@ -1,18 +1,14 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import render
from .models import Repo, Label from .models import Repo
def index(request): def index(request):
repo_list = Repo.objects.all() repo_list = Repo.objects.all()
label_list = Label.objects.all()
# template = loader.get_template('borg/index.html') hour_list = [repo.get_archive_hours_dict() for repo in repo_list]
context = { context = {
'repo_list': repo_list, 'repo_list': repo_list,
'label_list': label_list, 'hour_list': hour_list
} }
# return HttpResponse(template.render(context, request))
return render(request, 'borg/index.html', context) return render(request, 'borg/index.html', context)