From 45ccfff5354a9bc97152942a241218330be7c395 Mon Sep 17 00:00:00 2001 From: susanodd Date: Tue, 25 Jun 2024 08:45:55 +0200 Subject: [PATCH] #1268: Added more feedback for text fields batch edit. --- media/js/glosses_toggle_edit.js | 21 ++++++++++++------- signbank/dictionary/batch_edit.py | 21 +++++++++++++++++-- .../dictionary/admin_batch_edit_view.html | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/media/js/glosses_toggle_edit.js b/media/js/glosses_toggle_edit.js index 1ed23b0e..a3f71674 100644 --- a/media/js/glosses_toggle_edit.js +++ b/media/js/glosses_toggle_edit.js @@ -119,14 +119,21 @@ function toggle_language_fields(data) { }; var glossid = data.glossid; var errors = data.errors; - var errors_lookup = '#errors_' + glossid; - var errorsElt = $(errors_lookup); - var glossCell = "ERRORS "; - errorsElt.html(glossCell); + var status_lookup = '#status_' + glossid; + var statusElt = $(status_lookup); + statusCell = ""+updatestatus+""; + statusElt.html(statusCell); } $(document).ready(function() { diff --git a/signbank/dictionary/batch_edit.py b/signbank/dictionary/batch_edit.py index 864dcbb3..04820a43 100644 --- a/signbank/dictionary/batch_edit.py +++ b/signbank/dictionary/batch_edit.py @@ -156,7 +156,8 @@ def check_constraints_on_gloss_language_fields(gloss, value_dict): lemmas_per_language_translation = dict() for language, lemmaidglosstranslation_text in lemmaidglosstranslations.items(): lemmatranslation_for_this_text_language = LemmaIdglossTranslation.objects.filter( - lemma__dataset=dataset, language=language, text__iexact=lemmaidglosstranslation_text) + lemma__dataset=dataset, language=language, + text__iexact=lemmaidglosstranslation_text).exclude(lemma=gloss.lemma) lemmas_per_language_translation[language] = lemmatranslation_for_this_text_language existing_lemmas = [] @@ -174,7 +175,8 @@ def check_constraints_on_gloss_language_fields(gloss, value_dict): annotations_per_language_translation = dict() for language, annotationidglosstranslation_text in annotationidglosstranslations.items(): annotationtranslation_for_this_text_language = AnnotationIdglossTranslation.objects.filter( - gloss__lemma__dataset=dataset, language=language, text__iexact=annotationidglosstranslation_text) + gloss__lemma__dataset=dataset, language=language, + text__iexact=annotationidglosstranslation_text).exclude(gloss=gloss) annotations_per_language_translation[language] = annotationtranslation_for_this_text_language existing_glosses = [] @@ -212,10 +214,19 @@ def batch_edit_update_gloss(request, glossid): if value_dict[key] != language_fields_dict[key]: fields_to_update[key] = value_dict[key] + if not fields_to_update: + print('nothing to do') + saved_text = gettext("No changes were found.") + result['glossid'] = glossid + result['errors'] = [] + result['updatestatus'] = saved_text + return result + errors = check_constraints_on_gloss_language_fields(gloss, fields_to_update) if errors: result['glossid'] = glossid result['errors'] = errors + result['updatestatus'] = "❌" return result for key in fields_to_update.keys(): @@ -230,4 +241,10 @@ def batch_edit_update_gloss(request, glossid): add_gloss_update_to_revision_history(request.user, gloss, 'annotation_'+language, original_value, newvalue) gloss.lastUpdated = DT.datetime.now(tz=get_current_timezone()) gloss.save() + + saved_text = gettext("Gloss saved to dataset") + result['glossid'] = glossid + result['errors'] = [] + result['updatestatus'] = saved_text + " ✓" + return result diff --git a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html index 47007e6f..65ceef56 100644 --- a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html +++ b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html @@ -456,7 +456,7 @@

{% trans "On initial view, the most recent query results are shown." %}

- +