Skip to content

Commit

Permalink
#1268: Added handshape change to phonology.
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jul 10, 2024
1 parent 3a2b225 commit c14289c
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
32 changes: 32 additions & 0 deletions media/js/glosses_toggle_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ function toggle_subhndsh(data) {
buttonCell.attr('value', button_contents);
}

function toggle_handCh(data) {
if ($.isEmptyObject(data)) {
return;
};
var glossid = data.glossid;
var handCh = data.handCh;
var hCell = $("#handCh_cell_"+glossid);
$(hCell).empty();
var cell = "<span class='handCh'>"+handCh+"</span>";
hCell.html(cell);

var button_lookup = '#button_' + glossid + '_handCh';
var buttonCell = $(button_lookup);
var button_contents = similar_gloss_fields_labels['handCh'] + ': ' + handCh;
buttonCell.attr('value', button_contents);
}

function toggle_locprim(data) {
if ($.isEmptyObject(data)) {
return;
Expand Down Expand Up @@ -402,6 +419,21 @@ $(document).ready(function() {
success : toggle_subhndsh
});
});

$('.quick_handCh').click(function(e)
{
e.preventDefault();
var glossid = $(this).attr('value');
var handCh = $(this).attr("data-handCh");
$.ajax({
url : url + "/dictionary/update/toggle_handCh/" + glossid + "/" + handCh,
type: 'POST',
data: { 'csrfmiddlewaretoken': csrf_token },
datatype: "json",
success : toggle_handCh
});
});

$('.quick_locprim').click(function(e)
{
e.preventDefault();
Expand Down
9 changes: 8 additions & 1 deletion signbank/dictionary/adminviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6539,7 +6539,8 @@ def get_context_data(self, **kwargs):

context['available_tags'] = [tag for tag in Tag.objects.all()]

similar_gloss_fields = ['handedness', 'domhndsh', 'subhndsh', 'locprim', 'movSh', 'repeat', 'altern']
similar_gloss_fields = ['handedness', 'domhndsh', 'subhndsh', 'handCh', 'locprim',
'movSh', 'repeat', 'altern']
context['similar_gloss_fields'] = json.dumps(similar_gloss_fields)
similar_gloss_fields_labels = {}
for field in similar_gloss_fields:
Expand All @@ -6561,6 +6562,12 @@ def get_context_data(self, **kwargs):
machine_value__gt=1).order_by('name')]
context['available_handshape'] = available_handshape

available_handCh = [fc for fc in FieldChoice.objects.filter(
field='HandshapeChange', machine_value__in=[0, 1]).order_by('machine_value')]
available_handCh += [fc for fc in FieldChoice.objects.filter(
field='HandshapeChange', machine_value__gt=1).order_by('name')]
context['available_handCh'] = available_handCh

available_locprim = [fc for fc in FieldChoice.objects.filter(
field='Location', machine_value__in=[0, 1]).order_by('machine_value')]
available_locprim += [fc for fc in FieldChoice.objects.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,14 @@ <h3>{% trans "Batch Edit" %}</h3>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Handshape Change" %}</th>
<td class="field_handCh" style="width:100px;">
<div class="handCh-cell"
id="handCh_cell_{{gloss.id}}"><span class='handCh'>{% if gloss.handCh %}{{gloss.handCh.name}}{% endif %}</span>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Location" %}</th>
<td class="field_locprim" style="width:100px;">
Expand Down Expand Up @@ -639,6 +647,25 @@ <h3>{% trans "Batch Edit" %}</h3>
</div>
</div>

<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#phonology"
data-target='#toggle_handCh_panel_{{gloss.id}}'>{% trans "Handshape Change" %}
</div>
<div id='toggle_handCh_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
<p>
{% for wc in available_handCh %}
<button id='quick_handCh_btn_{{gloss.id}}' class="quick_handCh btn actionButton"
name='quick_handCh_{{gloss.id}}'
value='{{gloss.id}}' data-handCh='{{wc.machine_value}}' style="height:36px;"
type="submit" >{{wc.name}}
</button>
{% endfor %}
</p>
</div>
</div>
</div>

<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#phonology"
data-target='#toggle_locprim_panel_{{gloss.id}}'>{% trans "Location" %}
Expand All @@ -656,6 +683,7 @@ <h3>{% trans "Batch Edit" %}</h3>
</p>
</div>
</div>
</div>

<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#phonology"
Expand Down
16 changes: 15 additions & 1 deletion signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
from signbank.dictionary.update_glosses import (mapping_toggle_tag, mapping_toggle_semanticfield,
mapping_toggle_wordclass, mapping_toggle_namedentity,
mapping_toggle_handedness, mapping_toggle_domhndsh,
mapping_toggle_subhndsh, mapping_toggle_locprim, mapping_toggle_movSh,
mapping_toggle_subhndsh, mapping_toggle_handCh, mapping_toggle_locprim,
mapping_toggle_movSh,
batch_edit_create_sense, mapping_toggle_repeat, mapping_toggle_altern)
from signbank.dictionary.batch_edit import batch_edit_update_gloss

Expand Down Expand Up @@ -3568,6 +3569,19 @@ def toggle_subhndsh(request, glossid, subhndsh):
return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_handCh(request, glossid, handCh):

gloss = Gloss.objects.filter(id=glossid).first()

if not okay_to_update_gloss(request, gloss):
return JsonResponse({})

result = mapping_toggle_handCh(request, gloss, handCh)

return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_locprim(request, glossid, locprim):

Expand Down
38 changes: 38 additions & 0 deletions signbank/dictionary/update_glosses.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,44 @@ def mapping_toggle_subhndsh(request, gloss, subhndsh):
return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_handCh(request, gloss, handCh):

try:
handCh_machine_value = int(handCh)
except TypeError:
return {}

empty_handCh = FieldChoice.objects.get(field='HandshapeChange', machine_value=0)
new_handCh = FieldChoice.objects.filter(field='HandshapeChange', machine_value=handCh_machine_value).first()

if not new_handCh:
# if the word class does not exist, set it to empty
handCh_machine_value = 0
new_handCh = empty_handCh

original_handCh = gloss.handCh.name if gloss.handCh else '-'

with atomic():
if not gloss.handCh:
gloss.handCh = new_handCh
elif gloss.handCh.machine_value != handCh_machine_value:
gloss.handCh = new_handCh
else:
gloss.handCh = empty_handCh
new_handCh = empty_handCh
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'handCh', original_handCh, new_handCh.name)

result = dict()
result['glossid'] = str(gloss.id)
newvalue = gloss.handCh.name
result['handCh'] = newvalue

return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_locprim(request, gloss, locprim):

Expand Down
3 changes: 3 additions & 0 deletions signbank/dictionary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
re_path(r'^update/toggle_subhndsh/(?P<glossid>\d+)/(?P<subhndsh>.*)$',
signbank.dictionary.update.toggle_subhndsh,
name='toggle_subhndsh'),
re_path(r'^update/toggle_handCh/(?P<glossid>\d+)/(?P<handCh>.*)$',
signbank.dictionary.update.toggle_handCh,
name='toggle_handCh'),
re_path(r'^update/toggle_locprim/(?P<glossid>\d+)/(?P<locprim>.*)$',
signbank.dictionary.update.toggle_locprim,
name='toggle_locprim'),
Expand Down

0 comments on commit c14289c

Please sign in to comment.