ytsm/app/YtManagerApp/views/actions.py

55 lines
1.5 KiB
Python
Raw Normal View History

from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import JsonResponse
from django.views.generic import View
2019-08-14 14:14:16 +00:00
from YtManagerApp.management.jobs.synchronize import SynchronizeJob
2019-11-22 17:11:52 +00:00
from YtManagerApp.models import Video, Subscription
class SyncNowView(LoginRequiredMixin, View):
def post(self, *args, **kwargs):
2019-11-22 17:11:52 +00:00
if 'pk' in kwargs:
SynchronizeJob.schedule_now_for_subscription(Subscription.objects.get(id=kwargs['pk']))
else:
SynchronizeJob.schedule_now()
return JsonResponse({
'success': True
})
class DeleteVideoFilesView(LoginRequiredMixin, View):
def post(self, *args, **kwargs):
video = Video.objects.get(id=kwargs['pk'])
video.delete_files()
return JsonResponse({
'success': True
})
class DownloadVideoFilesView(LoginRequiredMixin, View):
def post(self, *args, **kwargs):
video = Video.objects.get(id=kwargs['pk'])
video.download()
return JsonResponse({
'success': True
})
class MarkVideoWatchedView(LoginRequiredMixin, View):
def post(self, *args, **kwargs):
video = Video.objects.get(id=kwargs['pk'])
video.mark_watched()
return JsonResponse({
'success': True
})
class MarkVideoUnwatchedView(LoginRequiredMixin, View):
def post(self, *args, **kwargs):
video = Video.objects.get(id=kwargs['pk'])
video.mark_unwatched()
video.save()
return JsonResponse({
'success': True
})