Allow list of repos to be queried

This commit is contained in:
George Lacey 2022-04-06 12:19:17 +01:00
parent 1a72f9243d
commit 77550137f9
3 changed files with 7 additions and 2 deletions

View File

@ -7,6 +7,7 @@ urlpatterns = [
path('', cache_page(60)(views.index), name='index'), 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_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_monthly.json', cache_page(3600 * 12)(views.repo_monthly_json), name='monthly repo json'),
path('repo_list.json', cache_page(3600)(views.repo_list), name='repo list'),
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('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

@ -1,3 +1,3 @@
from .views import index, repo, axes from .views import index, repo, axes
from .post import post_repo, post_archive, post_error, post_location from .post import post_repo, post_archive, post_error, post_location
from .json import repo_daily_json, repo_monthly_json from .json import repo_daily_json, repo_monthly_json, repo_list

View File

@ -1,10 +1,14 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.http import JsonResponse from django.http import JsonResponse
from ..models import Repo from ..models import Repo, Label
from ..utility import data from ..utility import data
from ..utility.time import last_day_previous_months from ..utility.time import last_day_previous_months
def repo_list(request):
return JsonResponse({'labels': [repo.label.label for repo in Repo.objects.all()]})
def repo_monthly_json(request, months_ago: int = 12): def repo_monthly_json(request, months_ago: int = 12):
date_labels = [date.strftime("%b %Y") for date in last_day_previous_months(months_ago)] date_labels = [date.strftime("%b %Y") for date in last_day_previous_months(months_ago)]