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
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)
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)
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)
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 = {}
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):