Skip to content

Commit

Permalink
#1268: Added repeat to phonology fields (part 2).
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jul 10, 2024
1 parent 3785e27 commit f076118
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 12 deletions.
37 changes: 34 additions & 3 deletions media/js/glosses_toggle_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ function toggle_movSh(data) {
buttonCell.attr('value', button_contents);
}

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

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

function toggle_create_sense(data) {
if ($.isEmptyObject(data)) {
return;
Expand Down Expand Up @@ -396,6 +413,20 @@ $(document).ready(function() {
});
});

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

$('.quick_create_sense').click(function(e)
{
e.preventDefault();
Expand Down Expand Up @@ -451,9 +482,9 @@ $(document).ready(function() {
{
e.preventDefault();
var glossid = $(this).attr('data-glossid');
var similar_glosses_lookup = '#similar_gloss_videos_' + glossid;
var similar_glossesElt = $(similar_glosses_lookup);
similar_glossesElt.empty();
var similar_glosses_lookup = '#similar_gloss_videos_' + glossid;
var similar_glossesElt = $(similar_glosses_lookup);
similar_glossesElt.empty();
var query = { 'csrfmiddlewaretoken': csrf_token };
for (var i=0; i < similar_gloss_fields.length; i++) {
var fieldname = similar_gloss_fields[i];
Expand Down
21 changes: 15 additions & 6 deletions signbank/dictionary/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from tagging.models import TaggedItem, Tag

from django.db.models import When, Case, BooleanField, IntegerField
from signbank.dictionary.models import *
from signbank.dictionary.forms import *
from signbank.tools import get_default_annotationidglosstranslation
Expand Down Expand Up @@ -377,10 +378,12 @@ def get_similargloss_fields_dict(request):
def similar_glosses_fields(request, gloss):

fields = get_similargloss_fields_dict(request)

fields_dict = dict()
for field in fields:
for field in fields.keys():
gloss_value = getattr(gloss, field)
if isinstance(Gloss.get_field(field), BooleanField):
fields_dict[field] = gloss_value
continue
fields_dict[field] = gloss_value.machine_value if gloss_value else 0
return fields_dict

Expand All @@ -397,10 +400,16 @@ def similarglosses(request, gloss_id):

qs = Gloss.objects.filter(lemma__dataset=gloss.lemma.dataset).exclude(id=gloss.id)
for field, value in fields_dict.items():
if not value:
continue
query_filter = field + '__machine_value'
qs = qs.filter(**{query_filter: value})
if isinstance(Gloss.get_field(field), BooleanField):
query_filter = field + '__in'
query_value = [value]
elif not value:
query_filter = field + '__machine_value'
query_value = 0
else:
query_filter = field + '__machine_value'
query_value = value
qs = qs.filter(**{query_filter: query_value})

result = dict()
similar_glosses = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@
input[type="button"]:focus {
outline: none;
}
.similarButton.actionButton {
padding: 0px 8px 12px 8px;
height: 30px;
}
textarea {
border: none;
}
Expand Down Expand Up @@ -704,12 +708,12 @@ <h3>{% trans "Batch Edit" %}</h3>
<div class="panel-body" style="display:inline-block;">
<table class="table-responsive">
<tr>
<td style="line-height: 26px;">
<td style="line-height: 30px;">
{% load field_choice %}
{% for fieldname, label in similar_gloss_fields_labels.items %}
{% with gloss|get_gloss_field:fieldname as fieldvalue %}
<input name="button_{{gloss.id}}_{{fieldname}}" id="button_{{gloss.id}}_{{fieldname}}"
class="similar actionButton"
class="similar similarButton actionButton"
type='button' onclick="do_toggle_field(this);" data-glossid="{{gloss.id}}"
data-value="{{fieldname}}" style="text-decoration:none;color:black;"
value="{{label}}: {{fieldvalue}}">
Expand Down
15 changes: 14 additions & 1 deletion signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
mapping_toggle_wordclass, mapping_toggle_namedentity,
mapping_toggle_handedness, mapping_toggle_domhndsh,
mapping_toggle_subhndsh, mapping_toggle_locprim, mapping_toggle_movSh,
batch_edit_create_sense)
batch_edit_create_sense, mapping_toggle_repeat)
from signbank.dictionary.batch_edit import batch_edit_update_gloss


Expand Down Expand Up @@ -3594,6 +3594,19 @@ def toggle_movSh(request, glossid, movSh):
return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_repeat(request, glossid, repeat):

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

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

result = mapping_toggle_repeat(request, gloss, repeat)

return JsonResponse(result)


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

Expand Down
26 changes: 26 additions & 0 deletions signbank/dictionary/update_glosses.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,32 @@ def mapping_toggle_movSh(request, gloss, movSh):
return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_repeat(request, gloss, repeat):
# repeat is 0 or 1

if repeat not in ['0', '1']:
return {}

new_repeat_boolean = repeat == '1'

original_repeat = 'True' if gloss.repeat else 'False'
new_repeat = 'True' if repeat == '1' else 'False'

with atomic():
gloss.repeat = new_repeat_boolean
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'repeat', new_repeat, original_repeat)

result = dict()
result['glossid'] = str(gloss.id)
newvalue = gettext("Yes") if gloss.repeat else gettext("No")
result['repeat'] = newvalue

return result


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

Expand Down
3 changes: 3 additions & 0 deletions signbank/dictionary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
re_path(r'^update/toggle_movSh/(?P<glossid>\d+)/(?P<movSh>.*)$',
signbank.dictionary.update.toggle_movSh,
name='toggle_movSh'),
re_path(r'^update/toggle_repeat/(?P<glossid>\d+)/(?P<repeat>.*)$',
signbank.dictionary.update.toggle_repeat,
name='toggle_repeat'),

re_path(r'^update/quick_create_sense/(?P<glossid>\d+)$',
signbank.dictionary.update.quick_create_sense,
Expand Down

0 comments on commit f076118

Please sign in to comment.