book json
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 19 Mar 2024 11:36:01 +0000 (12:36 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 19 Mar 2024 11:36:01 +0000 (12:36 +0100)
src/archive/urls.py
src/archive/utils.py
src/archive/views.py

index b057df4..f8f2309 100644 (file)
@@ -9,6 +9,7 @@ urlpatterns = [
     path('move_to_archive/<path:filename>/', views.move_to_archive, name="move_to_archive"),
     path('publishing/', views.list_publishing, name="list_publishing"),
     path('book/<slug:slug>/', views.BookView.as_view(), name="book"),
     path('move_to_archive/<path:filename>/', views.move_to_archive, name="move_to_archive"),
     path('publishing/', views.list_publishing, name="list_publishing"),
     path('book/<slug:slug>/', views.BookView.as_view(), name="book"),
+    path('book/<slug:slug>.json', views.book_json, name="book_json"),
     path('book-youtube-volume/<int:aid>/', views.book_youtube_volume, name="book_youtube_volume"),
     path('file/<int:id>/', views.file_managed, name="file"),
     path('publish/<int:aid>/', views.publish, name="publish"),
     path('book-youtube-volume/<int:aid>/', views.book_youtube_volume, name="book_youtube_volume"),
     path('file/<int:id>/', views.file_managed, name="file"),
     path('publish/<int:aid>/', views.publish, name="publish"),
index 35f7a74..e09f325 100644 (file)
@@ -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:
     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("/")
             yield os.path.join(path, fname)[root_len:].lstrip("/")
index 6ae2927..b4a3696 100644 (file)
@@ -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.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
 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)
 
             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):
 
 @permission_required('archive.change_audiobook')
 def book_youtube_volume(request, aid):