Commit 3c3c8c4f authored by Ilya Simonov's avatar Ilya Simonov

add save video to playlist if update playlist

parent 15e41312
......@@ -2,7 +2,7 @@ from django.conf import settings
from django.dispatch import receiver
from django.db.models.signals import post_save
from . import models, tasks
from . import models, tasks, utils
@receiver(post_save, sender=models.Video)
......@@ -17,3 +17,6 @@ def post_save_playlist(sender, instance, created, **kwargs):
instance.json = f'{settings.DOMAIN_NAME}/api/playlist/{instance.id}/'
instance.mrss = f'{settings.DOMAIN_NAME}/api/playlist/{instance.id}/mrss'
instance.save()
if instance.type == models.DYNAMIC:
utils.add_video_to_new_playlist(instance)
......@@ -6,10 +6,6 @@ from moviepy.editor import VideoFileClip
from .models import Video, Playlist, TagToObject, DYNAMIC
def asset_upload(instance, filename):
return f'videos/{filename}'
def generate_thumbnail(video_path, video_name):
clip = VideoFileClip(video_path)
thumbnail_name = video_name.split('.')[0]
......@@ -41,3 +37,23 @@ def add_video_to_playlist(video):
for playlist in playlists:
playlist.videos.add(video)
def add_video_to_new_playlist(playlist):
video_content_type = ContentType.objects.get_for_model(Video)
playlist_content_type = ContentType.objects.get_for_model(Playlist)
tag_ids = list(TagToObject.objects.filter(
content_type=playlist_content_type,
object_id=playlist.id,
).values_list('tag_id', flat=True))
if tag_ids:
video_ids = list(TagToObject.objects.filter(
content_type=video_content_type,
tag_id__in=tag_ids,
).values_list('object_id', flat=True))
if video_ids:
for video in Video.objects.filter(id__in=video_ids):
playlist.videos.add(video)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment