2018-10-27 00:33:45 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.http import JsonResponse
|
|
|
|
from django.views.generic import View
|
|
|
|
|
2018-10-20 22:20:31 +00:00
|
|
|
from YtManagerApp.management.jobs.synchronize import schedule_synchronize_now
|
2018-10-27 00:33:45 +00:00
|
|
|
from YtManagerApp.models import Video
|
2018-10-20 22:20:31 +00:00
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class SyncNowView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
schedule_synchronize_now()
|
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class DeleteVideoFilesView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.delete_files()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class DownloadVideoFilesView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.download()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class MarkVideoWatchedView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.mark_watched()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class MarkVideoUnwatchedView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.mark_unwatched()
|
2018-10-20 22:20:31 +00:00
|
|
|
video.save()
|
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|