Implement individual repo json request methods

This commit is contained in:
George Lacey 2022-04-11 07:54:41 +01:00
parent 752ee31c47
commit 7a12406e60
2 changed files with 21 additions and 6 deletions

View File

@ -8,12 +8,16 @@ urlpatterns = [
path('', cache_page(60)(views.index), name='index'), path('', cache_page(60)(views.index), name='index'),
path('repo/<str:repo_label>', cache_page(60)(views.repo), name='repo'), path('repo/<str:repo_label>', cache_page(60)(views.repo), name='repo'),
path('repo_list.json', cache_page(60)(views.repo_list_json), name='repo list'), path('repo-list.json', cache_page(60)(views.repo_list_json), name='repo list'),
# Repo # Repo
path('repo/<str:repo_label>/monthly-size.json', cache_page(3600)(views.repo_monthly_size_json), path('repo/<str:repo_label>/monthly-size.json', cache_page(3600)(views.repo_monthly_size_json),
name='repo size time series'), name='repo size time series'),
path('repo/<str:repo_label>.json', cache_page(60)(views.repo_json), name='repo json'), path('repo/<str:repo_label>.json', cache_page(60)(views.repo_json), name='repo json'),
path('repo/<str:repo_label>/latest-backup.json', cache_page(60)(views.repo_latest_backup_json), name='repo json'),
path('repo/<str:repo_label>/size.json', cache_page(60)(views.repo_size_json), name='repo size json'),
path('repo/<str:repo_label>/recent-errors.json', cache_page(60)(views.repo_recent_errors_json),
name='repo recent errors json'),
# POST # POST
path('post/repo', views.post_repo, name='post repo'), path('post/repo', views.post_repo, name='post repo'),

View File

@ -8,15 +8,26 @@ from ..utility.time import last_day_previous_months
def repo_json(request, repo_label): def repo_json(request, repo_label):
repo = get_object_or_404(Repo, label__label=repo_label) repo = get_object_or_404(Repo, label__label=repo_label)
repo_dict = {'location': repo.location, repo_dict = {'warning': repo.warning(),
'latest_backup': repo.last_backup(),
'size': repo.size_string(),
'recent_errors': len(repo.recent_errors()),
'warning': repo.warning(),
'error': repo.error()} 'error': repo.error()}
return JsonResponse(repo_dict) return JsonResponse(repo_dict)
def repo_latest_backup_json(request, repo_label):
repo = get_object_or_404(Repo, label__label=repo_label)
return JsonResponse({"data": repo.last_backup()})
def repo_size_json(request, repo_label):
repo = get_object_or_404(Repo, label__label=repo_label)
return JsonResponse({"data": repo.size_string()})
def repo_recent_errors_json(request, repo_label):
repo = get_object_or_404(Repo, label__label=repo_label)
return JsonResponse({"data": len(repo.recent_errors())})
def repo_monthly_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) repo = get_object_or_404(Repo, label__label=repo_label)