fix
[audio.git] / src / archive / views.py
index 0b5a5ac..c4dde17 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.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
@@ -70,9 +70,8 @@ def file_new(request, filename):
 def move_to_archive(request, filename):
     """ move a new file to the unmanaged files dir """
 
-    filename_str = filename.encode('utf-8')
-    old_path = os.path.join(settings.NEW_PATH, filename_str)
-    new_path = os.path.join(settings.UNMANAGED_PATH, filename_str)
+    old_path = os.path.join(settings.NEW_PATH, filename)
+    new_path = os.path.join(settings.UNMANAGED_PATH, filename)
     new_dir = os.path.split(new_path)[0]
     if not os.path.isdir(new_dir):
         os.makedirs(new_dir)
@@ -131,9 +130,8 @@ def remove_to_archive(request, aid):
 def move_to_new(request, filename):
     """ move a unmanaged file to new files dir """
 
-    filename_str = filename.encode('utf-8')
-    old_path = os.path.join(settings.UNMANAGED_PATH, filename_str)
-    new_path = os.path.join(settings.NEW_PATH, filename_str)
+    old_path = os.path.join(settings.UNMANAGED_PATH, filename)
+    new_path = os.path.join(settings.NEW_PATH, filename)
     new_dir = os.path.split(new_path)[0]
     if not os.path.isdir(new_dir):
         os.makedirs(new_dir)
@@ -157,9 +155,7 @@ def move_to_new(request, filename):
 def publish(request, aid, publish=True):
     """ mark file for publishing """
     audiobook = get_object_or_404(models.Audiobook, id=aid)
-    audiobook.prepare_for_publish()
-    if publish:
-        audiobook.publish(request.user)
+    audiobook.publish(request.user, publish=publish)
     return redirect(file_managed, aid)
 
 
@@ -276,7 +272,7 @@ def list_unmanaged(request):
 
 
 def file_unmanaged(request, filename):
-    tags = mutagen.File(os.path.join(settings.UNMANAGED_PATH, filename.encode('utf-8')))
+    tags = mutagen.File(os.path.join(settings.UNMANAGED_PATH, filename))
     if not tags:
         tags = {}
     
@@ -305,6 +301,27 @@ 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(),
+                "project": {
+                    "name": item.project.name,
+                    "can_sell": item.project.can_sell,
+                }
+            }
+            for item in qs
+        ]
+    })
+    
 
 @permission_required('archive.change_audiobook')
 def book_youtube_volume(request, aid):