Load daily repo graph separately

This commit is contained in:
George Lacey 2021-05-19 21:01:32 +01:00
parent a3c48a35b9
commit 2705641d0d
4 changed files with 15 additions and 10 deletions

View File

@ -1,6 +1,7 @@
window.addEventListener("DOMContentLoaded", function () { window.addEventListener("DOMContentLoaded", function () {
// const repoDict = JSON.parse(document.getElementById('hour_list').textContent); $.getJSON( "repo_daily.json", function( json ) {
// set_daily_graph(repoDict) set_daily_graph(json);
});
}, false); }, false);
function set_daily_graph(repoDict) { function set_daily_graph(repoDict) {

View File

@ -12,8 +12,8 @@
<link type="text/x-scss" href="{% static 'theme.scss' %}" rel="stylesheet" media="screen"> <link type="text/x-scss" href="{% static 'theme.scss' %}" rel="stylesheet" media="screen">
{% endcompress %} {% endcompress %}
{% block script %} <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
{% endblock %} {% block script %}{% endblock %}
<style>{% block style %}{% endblock %}</style> <style>{% block style %}{% endblock %}</style>
<title>{% block title %}Title{% endblock %}</title> <title>{% block title %}Title{% endblock %}</title>

View File

@ -5,6 +5,7 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', cache_page(60)(views.index), name='index'), path('', cache_page(60)(views.index), name='index'),
path('repo_daily.json', views.repo_daily_json, name='repo json'),
path('repo/<str:repo_label>', views.repo, name='repo'), path('repo/<str:repo_label>', views.repo, name='repo'),
path('post/repo', views.post_repo, name='post repo'), path('post/repo', views.post_repo, name='post repo'),
path('post/archive', views.post_archive, name='post archive'), path('post/archive', views.post_archive, name='post archive'),

View File

@ -2,23 +2,21 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import permission_required
from django.core.cache import cache
from django.http import JsonResponse
from .models import Repo, Label, Archive, Cache, Error, Location from .models import Repo, Label, Archive, Cache, Error, Location
from .forms import RepoForm, ArchiveForm, ErrorForm, LocationForm from .forms import RepoForm, ArchiveForm, ErrorForm, LocationForm
from django.contrib.auth.decorators import permission_required
from .utility import data
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.core.cache import cache from .utility import data
def index(request): def index(request):
repo_list = Repo.objects.all() repo_list = Repo.objects.all()
location_list = Location.objects.all() location_list = Location.objects.all()
# repo_dict = repo_daily_dict(repo_list, 8)
context = { context = {
'repo_list': repo_list, 'repo_list': repo_list,
# 'hour_list': repo_dict,
'location_list': location_list, 'location_list': location_list,
} }
return render(request, 'borg/index.html', context) return render(request, 'borg/index.html', context)
@ -38,6 +36,11 @@ def repo_daily_dict(repo_list, n_days=14):
} }
def repo_daily_json(request):
repo_list = Repo.objects.all()
return JsonResponse(repo_daily_dict(repo_list, 31))
def repo(request, repo_label: str): def repo(request, repo_label: str):
s_repo = get_object_or_404(Repo, label__label=repo_label) s_repo = get_object_or_404(Repo, label__label=repo_label)
return render(request, 'borg/repo.html', {'repo': s_repo}) return render(request, 'borg/repo.html', {'repo': s_repo})