Skip to content

Commit

Permalink
#1268: Batch edit weak hand and location
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jun 23, 2024
1 parent 080f347 commit 278b794
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 14 deletions.
52 changes: 51 additions & 1 deletion media/js/glosses_toggle_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ function toggle_domhndsh(data) {
hCell.html(cell);
}

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

function toggle_locprim(data) {
if ($.isEmptyObject(data)) {
return;
};
var glossid = data.glossid;
var locprim = data.locprim;
var hCell = $("#locprim_cell_"+glossid);
$(hCell).empty();
var cell = "<span class='locprim'>"+locprim+"</span>";
hCell.html(cell);
}
$(document).ready(function() {

// setup required for Ajax POST
Expand Down Expand Up @@ -189,5 +212,32 @@ $(document).ready(function() {
success : toggle_domhndsh
});
});

$('.quick_subhndsh').click(function(e)
{
e.preventDefault();
console.log('subhndsh');
var glossid = $(this).attr('value');
var subhndsh = $(this).attr("data-subhndsh");
$.ajax({
url : url + "/dictionary/update/toggle_subhndsh/" + glossid + "/" + subhndsh,
type: 'POST',
data: { 'csrfmiddlewaretoken': csrf_token },
datatype: "json",
success : toggle_subhndsh
});
});
$('.quick_locprim').click(function(e)
{
e.preventDefault();
console.log('locprim');
var glossid = $(this).attr('value');
var locprim = $(this).attr("data-locprim");
$.ajax({
url : url + "/dictionary/update/toggle_locprim/" + glossid + "/" + locprim,
type: 'POST',
data: { 'csrfmiddlewaretoken': csrf_token },
datatype: "json",
success : toggle_locprim
});
});
});
3 changes: 3 additions & 0 deletions signbank/dictionary/adminviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6537,6 +6537,9 @@ def get_context_data(self, **kwargs):
context['available_handshape'] = [wc for wc in Handshape.objects.filter(
machine_value__gt=1).order_by('name')]

context['available_locprim'] = [h for h in FieldChoice.objects.filter(
field='Location', machine_value__gt=1).order_by('name')]

# data structures to store the query parameters in order to keep them in the form
context['query_parameters'] = json.dumps(self.query_parameters)
query_parameters_keys = list(self.query_parameters.keys())
Expand Down
70 changes: 59 additions & 11 deletions signbank/dictionary/templates/dictionary/admin_batch_edit_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,7 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
{% endfor %}
{% endwith %}
<tr>
<th>{% trans "Handedness" %}</th>
<!-- <td>-->
<!-- <input name="handedness_{{gloss.id}}" id="handedness_{{gloss.id}}"-->
<!-- maxlength="200" type="text" size="50" value="{{gloss.display_handedness}}">-->
<!-- </td>-->
<th>{% trans "Handedness" %}</th>
<td class="field_handedness" style="width:100px;">
<div class="handedness-cell"
id="handedness_cell_{{gloss.id}}"><span class='handedness'>{% if gloss.handedness %}{{gloss.handedness.name}}{% endif %}</span>
Expand All @@ -406,17 +402,30 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
</tr>

<tr>
<th>{% trans "Sterke Hand" %}</th>
<!-- <td>-->
<!-- <input name="domhndsh_{{gloss.id}}" id="domhndsh_{{gloss.id}}"-->
<!-- maxlength="200" type="text" size="50" value="{{gloss.display_domhndsh}}">-->
<!-- </td>-->
<th>{% trans "Strong Hand" %}</th>
<td class="field_domhndsh" style="width:100px;">
<div class="domhndsh-cell"
id="domhndsh_cell_{{gloss.id}}"><span class='domhndsh'>{% if gloss.domhndsh %}{{gloss.domhndsh.name}}{% endif %}</span>
</div>
</td>
</tr>

<tr>
<th>{% trans "Weak Hand" %}</th>
<td class="field_subhndsh" style="width:100px;">
<div class="subhndsh-cell"
id="subhndsh_cell_{{gloss.id}}"><span class='subhndsh'>{% if gloss.subhndsh %}{{gloss.subhndsh.name}}{% endif %}</span>
</div>
</td>
</tr>
<tr>
<th>{% trans "Location" %}</th>
<td class="field_locprim" style="width:100px;">
<div class="locprim-cell"
id="locprim_cell_{{gloss.id}}"><span class='locprim'>{% if gloss.locprim %}{{gloss.locprim.name}}{% endif %}</span>
</div>
</td>
</tr>
</table>
</td>
<td style="width:500px;">
Expand Down Expand Up @@ -459,7 +468,7 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
</div>
<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#toggles"
data-target='#toggle_domhndsh_panel_{{gloss.id}}'>{% trans "Sterke Hand" %}
data-target='#toggle_domhndsh_panel_{{gloss.id}}'>{% trans "Strong Hand" %}
</div>
<div id='toggle_domhndsh_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
Expand All @@ -475,6 +484,45 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
</div>
</div>
</div>

<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#toggles"
data-target='#toggle_subhndsh_panel_{{gloss.id}}'>{% trans "Weak Hand" %}
</div>
<div id='toggle_subhndsh_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
<p>
{% for wc in available_handshape %}
<button id='quick_subhndsh_btn_{{gloss.id}}' class="quick_subhndsh btn actionButton"
name='quick_subhndsh_{{gloss.id}}'
value='{{gloss.id}}' data-subhndsh='{{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="#toggles"
data-target='#toggle_locprim_panel_{{gloss.id}}'>{% trans "Location" %}
</div>
<div id='toggle_locprim_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
<p>
{% for wc in available_locprim %}
<button id='quick_locprim_btn_{{gloss.id}}' class="quick_locprim btn actionButton"
name='quick_locprim_{{gloss.id}}'
value='{{gloss.id}}' data-locprim='{{wc.machine_value}}' style="height:36px;"
type="submit" >{{wc.name}}
</button>
{% endfor %}
</p>
</div>
</div>
</div>

</div>
</td>
{% tags_for_object gloss as tag_list %}
Expand Down
31 changes: 29 additions & 2 deletions signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
from signbank.dictionary.consistency_senses import reorder_translations
from signbank.dictionary.related_objects import gloss_related_objects, morpheme_related_objects
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_wordclass, mapping_toggle_namedentity,
mapping_toggle_handedness, mapping_toggle_domhndsh,
mapping_toggle_subhndsh, mapping_toggle_locprim)


def show_error(request, translated_message, form, dataset_languages):
Expand Down Expand Up @@ -3533,7 +3535,6 @@ def toggle_handedness(request, glossid, handedness):

@permission_required('dictionary.change_gloss')
def toggle_domhndsh(request, glossid, domhndsh):
print('toggle domhndsh')
if not request.user.is_authenticated:
return JsonResponse({})

Expand All @@ -3545,6 +3546,32 @@ def toggle_domhndsh(request, glossid, domhndsh):
return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_subhndsh(request, glossid, subhndsh):
if not request.user.is_authenticated:
return JsonResponse({})

if not request.user.has_perm('dictionary.change_gloss'):
return JsonResponse({})

result = mapping_toggle_subhndsh(request, glossid, subhndsh)

return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_locprim(request, glossid, locprim):
if not request.user.is_authenticated:
return JsonResponse({})

if not request.user.has_perm('dictionary.change_gloss'):
return JsonResponse({})

result = mapping_toggle_locprim(request, glossid, locprim)

return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def add_affiliation(request, glossid):
"""View to add an affiliation to a gloss"""
Expand Down
95 changes: 95 additions & 0 deletions signbank/dictionary/update_glosses.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,98 @@ def mapping_toggle_domhndsh(request, glossid, domhndsh):

return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_subhndsh(request, glossid, subhndsh):
if not request.user.is_authenticated:
return {}

if not request.user.has_perm('dictionary.change_gloss'):
return {}

try:
gloss_id = int(glossid)
except TypeError:
return {}

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

if not gloss:
return {}

try:
subhndsh_machine_value = int(subhndsh)
except TypeError:
return {}

empty_subhndsh = Handshape.objects.get(machine_value=0)
new_subhndsh = Handshape.objects.filter(machine_value=subhndsh_machine_value).first()

if not new_subhndsh:
# if the word class does not exist, set it to empty
subhndsh_machine_value = 0
new_subhndsh = empty_subhndsh

with atomic():
if not gloss.subhndsh:
gloss.subhndsh = new_subhndsh
elif gloss.subhndsh.machine_value != subhndsh_machine_value:
gloss.subhndsh = new_subhndsh
else:
gloss.subhndsh = empty_subhndsh
gloss.save()

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

return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_locprim(request, glossid, locprim):
if not request.user.is_authenticated:
return {}

if not request.user.has_perm('dictionary.change_gloss'):
return {}

try:
gloss_id = int(glossid)
except TypeError:
return {}

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

if not gloss:
return {}

try:
locprim_machine_value = int(locprim)
except TypeError:
return {}

empty_locprim = FieldChoice.objects.get(field='Location', machine_value=0)
new_locprim = FieldChoice.objects.filter(field='Location', machine_value=locprim_machine_value).first()

if not new_locprim:
# if the word class does not exist, set it to empty
locprim_machine_value = 0
new_locprim = empty_locprim

with atomic():
if not gloss.locprim:
gloss.locprim = new_locprim
elif gloss.locprim.machine_value != locprim_machine_value:
gloss.locprim = new_locprim
else:
gloss.locprim = empty_locprim
gloss.save()

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

return result
6 changes: 6 additions & 0 deletions signbank/dictionary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
re_path(r'^update/toggle_domhndsh/(?P<glossid>\d+)/(?P<domhndsh>.*)$',
signbank.dictionary.update.toggle_domhndsh,
name='toggle_domhndsh'),
re_path(r'^update/toggle_subhndsh/(?P<glossid>\d+)/(?P<subhndsh>.*)$',
signbank.dictionary.update.toggle_subhndsh,
name='toggle_subhndsh'),
re_path(r'^update/toggle_locprim/(?P<glossid>\d+)/(?P<locprim>.*)$',
signbank.dictionary.update.toggle_locprim,
name='toggle_locprim'),

# The next one does not have a permission check because it should be accessible from a cronjob
re_path(r'^update_ecv/', GlossListView.as_view(only_export_ecv=True)),
Expand Down

0 comments on commit 278b794

Please sign in to comment.