From c973bc9fda47d7dd437f346a5c18e4631da21687 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Mon, 11 Apr 2022 07:02:05 +0100 Subject: [PATCH] Organise views --- borgweb/borg/static/borg/js/index.js | 2 +- borgweb/borg/urls.py | 19 ++++++++++++++----- borgweb/borg/views/__init__.py | 2 +- borgweb/borg/views/json.py | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/borgweb/borg/static/borg/js/index.js b/borgweb/borg/static/borg/js/index.js index 68ecb13..8c5c5db 100644 --- a/borgweb/borg/static/borg/js/index.js +++ b/borgweb/borg/static/borg/js/index.js @@ -28,7 +28,7 @@ window.addEventListener("DOMContentLoaded", function () { inflateRepo(repo_json, repo_label, template, container); }) - $.getJSON(`/repo/${repo_label}/size.json`, function (repo_size_json) { + $.getJSON(`/repo/${repo_label}/monthly-size.json`, function (repo_size_json) { draw_time_series_graph(`repo-${repo_label}-size-graph`, repo_size_json.repo, repo_size_json.dates, repo_size_json.units); }) diff --git a/borgweb/borg/urls.py b/borgweb/borg/urls.py index c5c6693..4c38bc4 100644 --- a/borgweb/borg/urls.py +++ b/borgweb/borg/urls.py @@ -4,15 +4,24 @@ from django.views.decorators.cache import cache_page from . import views urlpatterns = [ + # Pages path('', cache_page(60)(views.index), name='index'), - path('repo_daily.json', cache_page(3600)(views.repo_daily_json), name='daily repo json'), - path('repo_monthly.json', cache_page(3600 * 12)(views.repo_monthly_json), name='monthly repo json'), - path('repo_list.json', cache_page(60)(views.repo_list_json), name='repo list'), - path('repo//size.json', cache_page(3600)(views.repo_size_json), name='repo size time series'), - path('repo/.json', cache_page(60)(views.repo_json), name='repo json'), path('repo/', cache_page(60)(views.repo), name='repo'), + + path('repo_list.json', cache_page(60)(views.repo_list_json), name='repo list'), + + # Repo + path('repo//monthly-size.json', cache_page(3600)(views.repo_monthly_size_json), + name='repo size time series'), + path('repo/.json', cache_page(60)(views.repo_json), name='repo json'), + + # POST path('post/repo', views.post_repo, name='post repo'), path('post/archive', views.post_archive, name='post archive'), path('post/error', views.post_error, name='post error'), path('post/location', views.post_location, name='post location'), + + # Unused + path('repo_daily.json', cache_page(3600)(views.repo_daily_json), name='daily repo json'), + path('repo_monthly.json', cache_page(3600 * 12)(views.repo_monthly_json), name='monthly repo json'), ] diff --git a/borgweb/borg/views/__init__.py b/borgweb/borg/views/__init__.py index 82ea75f..2b7cfeb 100644 --- a/borgweb/borg/views/__init__.py +++ b/borgweb/borg/views/__init__.py @@ -1,3 +1,3 @@ from .views import index, repo, axes from .post import post_repo, post_archive, post_error, post_location -from .json import repo_daily_json, repo_monthly_json, repo_list_json, repo_json, repo_size_json +from .json import repo_daily_json, repo_monthly_json, repo_list_json, repo_json, repo_monthly_size_json diff --git a/borgweb/borg/views/json.py b/borgweb/borg/views/json.py index 8d5ec70..a5d0cc1 100644 --- a/borgweb/borg/views/json.py +++ b/borgweb/borg/views/json.py @@ -17,7 +17,7 @@ def repo_json(request, repo_label): return JsonResponse(repo_dict) -def repo_size_json(request, repo_label, months_ago: int = 12): +def repo_monthly_size_json(request, repo_label, months_ago: int = 12): repo = get_object_or_404(Repo, label__label=repo_label) date_labels = [date.strftime("%b %Y") for date in last_day_previous_months(months_ago)]