Skip to content

Commit

Permalink
#1268: Added more feedback for text fields batch edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jun 25, 2024
1 parent c0207e3 commit 45ccfff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
21 changes: 14 additions & 7 deletions media/js/glosses_toggle_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ul>";
for (var err in errors) {
glossCell = glossCell + "<li>"+errors[err]+"</li>";
var updatestatus = data.updatestatus;
if (errors) {
var errors_lookup = '#errors_' + glossid;
var errorsElt = $(errors_lookup);
var glossCell = "<ul>";
for (var err in errors) {
glossCell = glossCell + "<li>"+errors[err]+"</li>";
}
glossCell = glossCell + "</ul>";
errorsElt.html(glossCell);
}
glossCell = glossCell + "</ul>";
errorsElt.html(glossCell);
var status_lookup = '#status_' + glossid;
var statusElt = $(status_lookup);
statusCell = "<span>"+updatestatus+"</span>";
statusElt.html(statusCell);
}

$(document).ready(function() {
Expand Down
21 changes: 19 additions & 2 deletions signbank/dictionary/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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 = []
Expand Down Expand Up @@ -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'] = "&#10060;"
return result

for key in fields_to_update.keys():
Expand All @@ -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 + " &#x2713;"

return result
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ <h4>{% trans "On initial view, the most recent query results are shown." %}</h4>
</button>
</span>
<p id="errors_{{gloss.id}}"></p>

<p id="status_{{gloss.id}}"></p>
</div>
</div>
</div>
Expand Down

0 comments on commit 45ccfff

Please sign in to comment.