From: Radek Czajka Date: Tue, 19 Mar 2024 11:36:01 +0000 (+0100) Subject: book json X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/2d950c51810e29fd54bf706fa01a74be065f881c book json --- diff --git a/src/archive/urls.py b/src/archive/urls.py index b057df4..f8f2309 100644 --- a/src/archive/urls.py +++ b/src/archive/urls.py @@ -9,6 +9,7 @@ urlpatterns = [ path('move_to_archive//', views.move_to_archive, name="move_to_archive"), path('publishing/', views.list_publishing, name="list_publishing"), path('book//', views.BookView.as_view(), name="book"), + path('book/.json', views.book_json, name="book_json"), path('book-youtube-volume//', views.book_youtube_volume, name="book_youtube_volume"), path('file//', views.file_managed, name="file"), path('publish//', views.publish, name="publish"), diff --git a/src/archive/utils.py b/src/archive/utils.py index 35f7a74..e09f325 100644 --- a/src/archive/utils.py +++ b/src/archive/utils.py @@ -39,4 +39,5 @@ def all_files(root_path): root_len = len(root_path) for path, dirs, files in os.walk(root_path, followlinks=True): for fname in files: + if '\n' in fname: continue yield os.path.join(path, fname)[root_len:].lstrip("/") diff --git a/src/archive/views.py b/src/archive/views.py index 6ae2927..b4a3696 100644 --- a/src/archive/views.py +++ b/src/archive/views.py @@ -8,7 +8,7 @@ from django.contrib.auth.decorators import permission_required from django.contrib.postgres.search import SearchVector from django.urls import reverse from django.db.models import Q, Max -from django.http import Http404, HttpResponse +from django.http import Http404, HttpResponse, JsonResponse from django.shortcuts import render, redirect, get_object_or_404 from django.utils.translation import gettext as _ from django.views.decorators.http import require_POST @@ -301,6 +301,23 @@ class BookView(ListView): b.subtotal = last_vol_sub.total_for_sub return list(qs) +def book_json(request, slug): + qs = models.Audiobook.objects.filter(slug=slug).order_by( + "index" + ) + return JsonResponse({ + "items": [ + { + "id": item.id, + "part": item.part_name, + "mp3_status": item.get_mp3_status_display(), + "ogg_status": item.get_ogg_status_display(), + "youtube_status": item.get_youtube_status_display(), + } + for item in qs + ] + }) + @permission_required('archive.change_audiobook') def book_youtube_volume(request, aid):