From 17713a094f533285c84bf9a8f8aac23c7b38b7c7 Mon Sep 17 00:00:00 2001 From: susanodd Date: Sat, 13 Jul 2024 10:19:53 +0200 Subject: [PATCH] #1268: Added Relative Orientation: Movement to phonology fields. --- media/js/glosses_toggle_edit.js | 31 +++++++++++++++ signbank/dictionary/adminviews.py | 8 +++- .../dictionary/admin_batch_edit_view.html | 28 +++++++++++++- signbank/dictionary/update.py | 13 +++++++ signbank/dictionary/update_glosses.py | 38 +++++++++++++++++++ signbank/dictionary/urls.py | 3 ++ 6 files changed, 119 insertions(+), 2 deletions(-) diff --git a/media/js/glosses_toggle_edit.js b/media/js/glosses_toggle_edit.js index b9932f8ab..fc2a76bd9 100644 --- a/media/js/glosses_toggle_edit.js +++ b/media/js/glosses_toggle_edit.js @@ -252,6 +252,23 @@ function toggle_altern(data) { buttonCell.attr('value', button_contents); } +function toggle_relOriMov(data) { + if ($.isEmptyObject(data)) { + return; + }; + var glossid = data.glossid; + var relOriMov = data.relOriMov; + var hCell = $("#relOriMov_cell_"+glossid); + $(hCell).empty(); + var cell = ""+relOriMov+""; + hCell.html(cell); + + var button_lookup = '#button_' + glossid + '_relOriMov'; + var buttonCell = $(button_lookup); + var button_contents = similar_gloss_fields_labels['relOriMov'] + ': ' + relOriMov; + buttonCell.attr('value', button_contents); +} + function toggle_create_sense(data) { if ($.isEmptyObject(data)) { return; @@ -583,6 +600,20 @@ $(document).ready(function() { }); }); + $('.quick_relOriMov').click(function(e) + { + e.preventDefault(); + var glossid = $(this).attr('value'); + var relOriMov = $(this).attr("data-relOriMov"); + $.ajax({ + url : url + "/dictionary/update/toggle_relOriMov/" + glossid + "/" + relOriMov, + type: 'POST', + data: { 'csrfmiddlewaretoken': csrf_token }, + datatype: "json", + success : toggle_relOriMov + }); + }); + $('.quick_create_sense').click(function(e) { e.preventDefault(); diff --git a/signbank/dictionary/adminviews.py b/signbank/dictionary/adminviews.py index 4dcbcb2e3..c72b7fe13 100755 --- a/signbank/dictionary/adminviews.py +++ b/signbank/dictionary/adminviews.py @@ -6540,7 +6540,7 @@ def get_context_data(self, **kwargs): context['available_tags'] = [tag for tag in Tag.objects.all()] similar_gloss_fields = ['handedness', 'domhndsh', 'subhndsh', 'handCh', 'relatArtic', 'locprim', - 'contType', 'movSh', 'movDir', 'repeat', 'altern'] + 'contType', 'movSh', 'movDir', 'repeat', 'altern', 'relOriMov'] context['similar_gloss_fields'] = json.dumps(similar_gloss_fields) similar_gloss_fields_labels = {} for field in similar_gloss_fields: @@ -6602,6 +6602,12 @@ def get_context_data(self, **kwargs): {'machine_value': 0, 'name': gettext("No")}] context['available_boolean'] = available_boolean + available_relOriMov = [fc for fc in FieldChoice.objects.filter( + field='RelOriMov', machine_value__in=[0, 1]).order_by('machine_value')] + available_relOriMov += [fc for fc in FieldChoice.objects.filter( + field='RelOriMov', machine_value__gt=1).order_by('name')] + context['available_relOriMov'] = available_relOriMov + context['query_parameters'] = json.dumps(self.query_parameters) query_parameters_keys = list(self.query_parameters.keys()) context['query_parameters_keys'] = json.dumps(query_parameters_keys) diff --git a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html index 3d11a9fb1..44724daac 100644 --- a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html +++ b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html @@ -556,7 +556,14 @@

{% trans "Batch Edit" %}

- + + {% trans "Relative Orientation: Movement" %} + +
{% if gloss.relOriMov %}{{gloss.relOriMov.name}}{% endif %} +
+ + @@ -823,6 +830,25 @@

{% trans "Batch Edit" %}

+
+
{% trans "Relative Orientation: Movement" %} +
+
+
+

+ {% for wc in available_relOriMov %} + + {% endfor %} +

+
+
+
+ diff --git a/signbank/dictionary/update.py b/signbank/dictionary/update.py index 07e7bb7a5..d0f9bfe9a 100755 --- a/signbank/dictionary/update.py +++ b/signbank/dictionary/update.py @@ -3668,6 +3668,19 @@ def toggle_altern(request, glossid, altern): return JsonResponse(result) +@permission_required('dictionary.change_gloss') +def toggle_relOriMov(request, glossid, relOriMov): + + gloss = Gloss.objects.filter(id=glossid).first() + + if not okay_to_update_gloss(request, gloss): + return JsonResponse({}) + + result = mapping_toggle_relOriMov(request, gloss, relOriMov) + + return JsonResponse(result) + + @permission_required('dictionary.change_gloss') def toggle_language_fields(request, glossid): diff --git a/signbank/dictionary/update_glosses.py b/signbank/dictionary/update_glosses.py index 082f6c390..ad6053cf7 100644 --- a/signbank/dictionary/update_glosses.py +++ b/signbank/dictionary/update_glosses.py @@ -550,6 +550,44 @@ def mapping_toggle_altern(request, gloss, altern): return result +@permission_required('dictionary.change_gloss') +def mapping_toggle_relOriMov(request, gloss, relOriMov): + + try: + relOriMov_machine_value = int(relOriMov) + except TypeError: + return {} + + empty_relOriMov = FieldChoice.objects.get(field='RelOriMov', machine_value=0) + new_relOriMov = FieldChoice.objects.filter(field='RelOriMov', machine_value=relOriMov_machine_value).first() + + if not new_relOriMov: + # if the word class does not exist, set it to empty + relOriMov_machine_value = 0 + new_relOriMov = empty_relOriMov + + original_relOriMov = gloss.relOriMov.name if gloss.relOriMov else '-' + + with atomic(): + if not gloss.relOriMov: + gloss.relOriMov = new_relOriMov + elif gloss.relOriMov.machine_value != relOriMov_machine_value: + gloss.relOriMov = new_relOriMov + else: + gloss.relOriMov = empty_relOriMov + new_relOriMov = empty_relOriMov + gloss.save() + + add_gloss_update_to_revision_history(request.user, gloss, 'relOriMov', original_relOriMov, new_relOriMov.name) + + result = dict() + result['glossid'] = str(gloss.id) + newvalue = gloss.relOriMov.name + result['relOriMov'] = newvalue + + return result + + @permission_required('dictionary.change_gloss') def batch_edit_create_sense(request, gloss): diff --git a/signbank/dictionary/urls.py b/signbank/dictionary/urls.py index 8e0c9d2d4..ac72c2c38 100755 --- a/signbank/dictionary/urls.py +++ b/signbank/dictionary/urls.py @@ -123,6 +123,9 @@ re_path(r'^update/toggle_altern/(?P\d+)/(?P.*)$', signbank.dictionary.update.toggle_altern, name='toggle_altern'), + re_path(r'^update/toggle_relOriMov/(?P\d+)/(?P.*)$', + signbank.dictionary.update.toggle_relOriMov, + name='toggle_relOriMov'), re_path(r'^update/quick_create_sense/(?P\d+)$', signbank.dictionary.update.quick_create_sense,