fix: delete media (#1366)

This commit is contained in:
Markos Gogoulos
2025-09-01 20:06:49 +03:00
committed by GitHub
parent 817e16ac60
commit 7a1b32f1ba
3 changed files with 27 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Field, Layout, Submit
from crispy_forms.layout import HTML, Field, Layout, Submit
from django import forms
from django.conf import settings
@@ -241,6 +241,8 @@ class WhisperSubtitlesForm(forms.ModelForm):
self.fields['allow_whisper_transcribe_and_translate'].widget.attrs['readonly'] = True
self.fields['allow_whisper_transcribe_and_translate'].widget.attrs['disabled'] = True
both_readonly = self.instance.allow_whisper_transcribe and self.instance.allow_whisper_transcribe_and_translate
self.helper = FormHelper()
self.helper.form_tag = True
self.helper.form_class = 'post-form'
@@ -252,7 +254,13 @@ class WhisperSubtitlesForm(forms.ModelForm):
CustomField('allow_whisper_transcribe_and_translate'),
)
self.helper.layout.append(FormActions(Submit('submit_whisper', 'Submit', css_class='primaryAction')))
if not both_readonly:
self.helper.layout.append(FormActions(Submit('submit_whisper', 'Submit', css_class='primaryAction')))
else:
# Optional: Add a disabled button with explanatory text
self.helper.layout.append(
FormActions(Submit('submit_whisper', 'Submit', css_class='primaryAction', disabled=True), HTML('<small class="text-muted">Cannot submit - both options are already enabled</small>'))
)
def clean_allow_whisper_transcribe(self):
# Ensure the field value doesn't change if it was originally True

View File

@@ -235,6 +235,8 @@ class Media(models.Model):
self.__original_media_file = self.media_file
self.__original_thumbnail_time = self.thumbnail_time
self.__original_uploaded_poster = self.uploaded_poster
self.__original_allow_whisper_transcribe = self.allow_whisper_transcribe
self.__original_allow_whisper_transcribe_and_translate = self.allow_whisper_transcribe_and_translate
def save(self, *args, **kwargs):
if not self.title:
@@ -275,6 +277,17 @@ class Media(models.Model):
if self.thumbnail_time != self.__original_thumbnail_time:
self.__original_thumbnail_time = self.thumbnail_time
self.set_thumbnail(force=True)
transcription_changed = (
self.allow_whisper_transcribe != self.__original_allow_whisper_transcribe or self.allow_whisper_transcribe_and_translate != self.__original_allow_whisper_transcribe_and_translate
)
if transcription_changed and self.media_type == "video":
self.transcribe_function()
# Update the original values for next comparison
self.__original_allow_whisper_transcribe = self.allow_whisper_transcribe
self.__original_allow_whisper_transcribe_and_translate = self.allow_whisper_transcribe_and_translate
else:
# media is going to be created now
# after media is saved, post_save signal will call media_init function
@@ -989,8 +1002,6 @@ def media_save(sender, instance, created, **kwargs):
tag.update_tag_media()
instance.update_search_vector()
if instance.media_type == "video":
instance.transcribe_function()
@receiver(pre_delete, sender=Media)