Allow syncing a single channel

This commit is contained in:
Jacob Mansfield [root@Helix] 2019-11-22 17:11:52 +00:00
parent 794b9bd42d
commit 85092935a6
4 changed files with 24 additions and 3 deletions

View File

@ -162,6 +162,10 @@ class Subscription(models.Model):
def delete_subscription(self, keep_downloaded_videos: bool): def delete_subscription(self, keep_downloaded_videos: bool):
self.delete() self.delete()
def synchronize_now(self):
from YtManagerApp.management.jobs.synchronize import SynchronizeJob
SynchronizeJob.schedule_now_for_subscription(self)
class Video(models.Model): class Video(models.Model):
video_id = models.CharField(null=False, max_length=12) video_id = models.CharField(null=False, max_length=12)

View File

@ -18,4 +18,17 @@
{% block modal_footer %} {% block modal_footer %}
<input class="btn btn-primary" type="submit" value="Save" aria-label="Save"> <input class="btn btn-primary" type="submit" value="Save" aria-label="Save">
<input class="btn btn-secondary" type="button" value="Cancel" data-dismiss="modal" aria-label="Cancel"> <input class="btn btn-secondary" type="button" value="Cancel" data-dismiss="modal" aria-label="Cancel">
<input class="btn btn-secondary" type="button" value="Synchronize Now" aria-label="Synchronize Now" onclick="synchronizeChannelNow()">
{% endblock modal_footer %} {% endblock modal_footer %}
{% block modal_scripts %}
<script>
function synchronizeChannelNow() {
$.post("{% url 'ajax_action_sync_now' form.instance.pk %}", {
csrfmiddlewaretoken: '{{ csrf_token }}'
}, function() {
});
}
</script>
{% endblock %}

View File

@ -37,6 +37,7 @@ urlpatterns = [
# Ajax # Ajax
path('ajax/action/sync_now/', SyncNowView.as_view(), name='ajax_action_sync_now'), path('ajax/action/sync_now/', SyncNowView.as_view(), name='ajax_action_sync_now'),
path('ajax/action/sync_now/<int:pk>', SyncNowView.as_view(), name='ajax_action_sync_now'),
path('ajax/action/delete_video_files/<int:pk>', DeleteVideoFilesView.as_view(), name='ajax_action_delete_video_files'), path('ajax/action/delete_video_files/<int:pk>', DeleteVideoFilesView.as_view(), name='ajax_action_delete_video_files'),
path('ajax/action/download_video_files/<int:pk>', DownloadVideoFilesView.as_view(), name='ajax_action_download_video_files'), path('ajax/action/download_video_files/<int:pk>', DownloadVideoFilesView.as_view(), name='ajax_action_download_video_files'),
path('ajax/action/mark_video_watched/<int:pk>', MarkVideoWatchedView.as_view(), name='ajax_action_mark_video_watched'), path('ajax/action/mark_video_watched/<int:pk>', MarkVideoWatchedView.as_view(), name='ajax_action_mark_video_watched'),

View File

@ -3,11 +3,14 @@ from django.http import JsonResponse
from django.views.generic import View from django.views.generic import View
from YtManagerApp.management.jobs.synchronize import SynchronizeJob from YtManagerApp.management.jobs.synchronize import SynchronizeJob
from YtManagerApp.models import Video from YtManagerApp.models import Video, Subscription
class SyncNowView(LoginRequiredMixin, View): class SyncNowView(LoginRequiredMixin, View):
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
if 'pk' in kwargs:
SynchronizeJob.schedule_now_for_subscription(Subscription.objects.get(id=kwargs['pk']))
else:
SynchronizeJob.schedule_now() SynchronizeJob.schedule_now()
return JsonResponse({ return JsonResponse({
'success': True 'success': True