From 2705641d0df689cd052f09245e01d2a58396d654 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Wed, 19 May 2021 21:01:32 +0100 Subject: [PATCH] Load daily repo graph separately --- borgweb/borg/static/js/index.js | 5 +++-- borgweb/borg/templates/borg/base.html | 4 ++-- borgweb/borg/urls.py | 1 + borgweb/borg/views.py | 15 +++++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/borgweb/borg/static/js/index.js b/borgweb/borg/static/js/index.js index eba9093..a4cc890 100644 --- a/borgweb/borg/static/js/index.js +++ b/borgweb/borg/static/js/index.js @@ -1,6 +1,7 @@ window.addEventListener("DOMContentLoaded", function () { - // const repoDict = JSON.parse(document.getElementById('hour_list').textContent); - // set_daily_graph(repoDict) + $.getJSON( "repo_daily.json", function( json ) { + set_daily_graph(json); + }); }, false); function set_daily_graph(repoDict) { diff --git a/borgweb/borg/templates/borg/base.html b/borgweb/borg/templates/borg/base.html index 5399b12..924edaa 100644 --- a/borgweb/borg/templates/borg/base.html +++ b/borgweb/borg/templates/borg/base.html @@ -12,8 +12,8 @@ {% endcompress %} - {% block script %} - {% endblock %} + + {% block script %}{% endblock %} {% block title %}Title{% endblock %} diff --git a/borgweb/borg/urls.py b/borgweb/borg/urls.py index 802c993..9fd6ccf 100644 --- a/borgweb/borg/urls.py +++ b/borgweb/borg/urls.py @@ -5,6 +5,7 @@ from . import views urlpatterns = [ path('', cache_page(60)(views.index), name='index'), + path('repo_daily.json', views.repo_daily_json, name='repo json'), path('repo/', views.repo, name='repo'), path('post/repo', views.post_repo, name='post repo'), path('post/archive', views.post_archive, name='post archive'), diff --git a/borgweb/borg/views.py b/borgweb/borg/views.py index 533d6a5..7ee6a6a 100644 --- a/borgweb/borg/views.py +++ b/borgweb/borg/views.py @@ -2,23 +2,21 @@ from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect 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 .forms import RepoForm, ArchiveForm, ErrorForm, LocationForm -from django.contrib.auth.decorators import permission_required -from .utility import data from datetime import datetime, timedelta -from django.core.cache import cache +from .utility import data def index(request): repo_list = Repo.objects.all() location_list = Location.objects.all() - # repo_dict = repo_daily_dict(repo_list, 8) - context = { 'repo_list': repo_list, - # 'hour_list': repo_dict, 'location_list': location_list, } 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): s_repo = get_object_or_404(Repo, label__label=repo_label) return render(request, 'borg/repo.html', {'repo': s_repo})