From 905f8f155742c3569efce29b30ce8746924825d2 Mon Sep 17 00:00:00 2001 From: pampletousse Date: Fri, 24 Nov 2023 17:22:52 +0100 Subject: [PATCH] Try to fix mulitple transcription with new receiver --- pod/video/forms.py | 20 +++++++++++++++++++- pod/video/static/js/dashboard.js | 2 +- pod/video/views.py | 28 ---------------------------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/pod/video/forms.py b/pod/video/forms.py index b3b773868e..a724a2f16c 100644 --- a/pod/video/forms.py +++ b/pod/video/forms.py @@ -309,6 +309,10 @@ ) if USE_TRANSCRIPTION: + from ..video_encode_transcript import transcript + + TRANSCRIPT_VIDEO = getattr(settings, "TRANSCRIPT_VIDEO", "start_transcript") + transcript_help_text = OrderedDict( [ ( @@ -540,6 +544,14 @@ def launch_encode(sender, instance, created, **kwargs): encode_video(instance.id) +@receiver(post_save, sender=Video) +def launch_transcript(sender, instance, created, **kwargs): + if hasattr(instance, "launch_transcript") and instance.launch_transcript is True: + instance.launch_transcript = False + transcript_video = getattr(transcript, TRANSCRIPT_VIDEO) + transcript_video(instance.id) + + class VideoForm(forms.ModelForm): """Form class for Video editing.""" @@ -705,6 +717,9 @@ def save(self, commit=True, *args, **kwargs): if hasattr(self, "launch_encode"): video.launch_encode = self.launch_encode + + if hasattr(self, "launch_transcript"): + video.launch_transcript = self.launch_transcript return video def clean_date_delete(self): @@ -755,7 +770,10 @@ def clean(self): and hasattr(self.instance, "video") and cleaned_data["video"] != self.instance.video ) - + self.launch_transcript = ( + "transcript" in cleaned_data.keys() + and hasattr(self.instance, "transcript") + ) self.change_user = ( self.launch_encode is False and hasattr(self.instance, "encoding_in_progress") diff --git a/pod/video/static/js/dashboard.js b/pod/video/static/js/dashboard.js index e19daa0dd5..1fad7a7fc6 100644 --- a/pod/video/static/js/dashboard.js +++ b/pod/video/static/js/dashboard.js @@ -29,7 +29,7 @@ async function bulkUpdate() { // Init vars let formData = new FormData(); - let updateAction = action === "delete" || action === "transcript" ? action : "fields" ; + let updateAction = action === "delete" ? action : "fields" ; let updateFields = []; // Set updated field(s) diff --git a/pod/video/views.py b/pod/video/views.py index c2ecf3c15b..4b49600f66 100644 --- a/pod/video/views.py +++ b/pod/video/views.py @@ -653,10 +653,6 @@ def bulk_update(request): # Bulk delete deleted_videos, status = bulk_update_delete(request, videos_list) counter = len(deleted_videos) - elif update_action == "transcript": - # Bulk transcript - updated_videos, status = bulk_update_transcript(request, videos_list) - counter = len(updated_videos) else: pass @@ -737,30 +733,6 @@ def bulk_update_delete(request, videos_list): return deleted_videos, status -def bulk_update_transcript(request, videos_list): - """ - Perform bulk transcript for selected videos. - - Args: - request (Request): current HTTP Request. - videos_list (List[Video]): list of videos to be transcript. - - Returns: - updated_videos (List[string]): list of modified videos slugs. - status (number): HTTP status. - """ - status = 200 - updated_videos = [] - - try: - for video in videos_list: - video_transcript(request, video.slug) - updated_videos.append(video.slug) - except Exception: - status = 400 - return updated_videos, status - - def get_bulk_update_result(request, status, update_action, counter, delta, result): """ Build and return result object with updated status and message for bulk update action.