X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/201dd39ec21858e2b4e82dc7bed4bf6aea0262cb..HEAD:/src/archive/views.py?ds=inline diff --git a/src/archive/views.py b/src/archive/views.py index 4865203..c4dde17 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 @@ -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) @@ -274,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 = {} @@ -303,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):