From 4bc3ee350f5853b6cf4b4d4e1596d303b8d87547 Mon Sep 17 00:00:00 2001 From: susanodd Date: Wed, 15 Jan 2025 14:44:51 +0100 Subject: [PATCH 1/2] #1456: Modified still image folder to obtain from gloss not from video filename. This avoids the video extension needing to be removed from the existing video filename --- signbank/dictionary/adminviews.py | 4 ++-- signbank/video/convertvideo.py | 22 ++++++++++++---------- signbank/video/models.py | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/signbank/dictionary/adminviews.py b/signbank/dictionary/adminviews.py index 39dd07aa8..9f4dd5b8e 100755 --- a/signbank/dictionary/adminviews.py +++ b/signbank/dictionary/adminviews.py @@ -7587,8 +7587,8 @@ def fetch_video_stills_for_gloss(request, gloss_id): gloss = Gloss.objects.get(id=gloss_id, archived=False) - folder = gloss.idgloss + '-' + gloss_id - folder = folder.replace(' ', '_') + from signbank.video.convertvideo import get_folder_name + folder = get_folder_name(gloss) temp_location_frames = os.path.join(settings.GLOSS_IMAGE_DIRECTORY, "signbank-thumbnail-frames", folder) temp_video_frames_folder = os.path.join(settings.WRITABLE_FOLDER, settings.GLOSS_IMAGE_DIRECTORY, "signbank-thumbnail-frames", folder) diff --git a/signbank/video/convertvideo.py b/signbank/video/convertvideo.py index d4f347d7f..a88032aab 100755 --- a/signbank/video/convertvideo.py +++ b/signbank/video/convertvideo.py @@ -123,13 +123,18 @@ def probe_format(file): return r['inputvideoformat'] -def generate_image_sequence(sourcefile): - basename, _ = os.path.splitext(sourcefile.path) +def get_folder_name(gloss): + gloss_video_filename = gloss.idgloss + '-' + str(gloss.id) + filename = gloss_video_filename.replace(' ', '_') + folder_name = filename.replace('.', '-') + return folder_name + + +def generate_image_sequence(gloss, sourcefile): + temp_location_frames = os.path.join(settings.WRITABLE_FOLDER, settings.GLOSS_IMAGE_DIRECTORY, "signbank-thumbnail-frames") - filename, ext = os.path.splitext(os.path.basename(sourcefile.name)) - filename = filename.replace(' ', '_') - folder_name, _ = os.path.splitext(filename) + folder_name = get_folder_name(gloss) temp_video_frames_folder = os.path.join(temp_location_frames, folder_name) # Create the necessary subfolder if needed if not os.path.isdir(temp_location_frames): @@ -156,13 +161,10 @@ def generate_image_sequence(sourcefile): return stills -def remove_stills(sourcefile): - basename, _ = os.path.splitext(sourcefile.path) +def remove_stills(gloss): temp_location_frames = os.path.join(settings.WRITABLE_FOLDER, settings.GLOSS_IMAGE_DIRECTORY, "signbank-thumbnail-frames") - filename, ext = os.path.splitext(os.path.basename(sourcefile.name)) - filename = filename.replace(' ', '_') - folder_name, _ = os.path.splitext(filename) + folder_name = get_folder_name(gloss) temp_video_frames_folder = os.path.join(temp_location_frames, folder_name) # remove the temp files stills_pattern = temp_video_frames_folder+"/*.png" diff --git a/signbank/video/models.py b/signbank/video/models.py index 2447e1c4e..f15ef1495 100755 --- a/signbank/video/models.py +++ b/signbank/video/models.py @@ -703,11 +703,11 @@ def small_video(self, use_name=False): def make_image_sequence(self): - generate_image_sequence(self.videofile) + generate_image_sequence(self.gloss, self.videofile) def delete_image_sequence(self): - remove_stills(self.videofile) + remove_stills(self.gloss) def make_small_video(self): # this method is not called (bugs) From c6508ac9cab63921a32360fa516b289c6f5c4e85 Mon Sep 17 00:00:00 2001 From: susanodd Date: Thu, 16 Jan 2025 14:31:35 +0100 Subject: [PATCH 2/2] #1360: Moved senses field code for update gloss API earlier. --- signbank/gloss_update.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/signbank/gloss_update.py b/signbank/gloss_update.py index 0772a6f6a..fc082ff7d 100755 --- a/signbank/gloss_update.py +++ b/signbank/gloss_update.py @@ -311,7 +311,7 @@ def detect_type_related_problems_for_gloss_update(changes, dataset, language_cod continue if field in language_fields: continue - if field == "Senses": + if field in ['Senses', 'senses']: continue if isinstance(field, FieldChoiceForeignKey): field_choice_category = field.field_choice_category @@ -474,17 +474,17 @@ def gloss_update_do_changes(user, gloss, changes, language_code): handshape = Handshape.objects.get(name__iexact=new_value) setattr(gloss, field.name, handshape) changes_done.append((field.name, original_value, new_value)) + elif field in ["senses", "Senses"]: + original_senses = collect_revision_history_for_senses(gloss) + update_senses(gloss, new_value) + new_senses = collect_revision_history_for_senses(gloss) + changes_done.append((field.name, original_senses, new_senses)) elif field.name == 'semField': update_semantic_field(gloss, new_value, language_code) changes_done.append((field.name, original_value, new_value)) elif field.name == 'derivHist': update_derivation_history_field(gloss, new_value, language_code) changes_done.append((field.name, original_value, new_value)) - elif field.name == "senses" and isinstance(field, models.ManyToManyField): - original_senses = collect_revision_history_for_senses(gloss) - update_senses(gloss, new_value) - new_senses = collect_revision_history_for_senses(gloss) - changes_done.append((field.name, original_senses, new_senses)) else: # text field setattr(gloss, field.name, new_value) @@ -522,7 +522,6 @@ def gloss_update(gloss, update_fields_dict, language_code): dataset = gloss.lemma.dataset language_fields, api_fields_2024 = api_update_gloss_fields(dataset, language_code) human_readable_to_internal, human_readable_to_json = update_gloss_columns_to_value_dict_keys(dataset, language_code) - combined_fields = api_fields_2024 for language_field in language_fields: gloss_dict_language_field = human_readable_to_json[language_field]