1247c501dab5ad78f8e4b4d7e4f722708a441fbf
[audio.git] / src / youtube / views.py
1 from django.contrib.auth.decorators import permission_required
2 from django.shortcuts import redirect, get_object_or_404
3 from django.urls import reverse
4 from django.views.decorators.http import require_POST
5 from archive.constants import status
6 from archive.models import Audiobook
7 from . import tasks
8
9
10
11 @require_POST
12 @permission_required('archive.change_audiobook')
13 def publish(request, aid, publish=True):
14     audiobook = get_object_or_404(Audiobook, id=aid)
15     tags = {}
16     #audiobook.set_youtube_tags(tags)
17     audiobook.youtube_status = status.WAITING
18     audiobook.save(update_fields=['youtube_status'])
19     audiobook.youtube_task = tasks.YouTubeTask.delay(request.user.id, aid, publish).task_id
20     audiobook.save(update_fields=['youtube_task'])
21     return redirect(reverse('file', args=[aid]))