Skip to content

Commit

Permalink
#1268: Save batch edits in revision history
Browse files Browse the repository at this point in the history
Moved video to same table cell table as gloss affiliation and creator
  • Loading branch information
susanodd committed Jun 24, 2024
1 parent 278b794 commit 22efca9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
15 changes: 12 additions & 3 deletions signbank/dictionary/adminviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6531,14 +6531,23 @@ def get_context_data(self, **kwargs):
context['available_semanticfields'] = [semfield for semfield in SemanticField.objects.filter(
machine_value__gt=1).order_by('name')]

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

context['available_handshape'] = [wc for wc in Handshape.objects.filter(
available_handshape = [hs for hs in Handshape.objects.filter(
machine_value__in=[0, 1]).order_by('machine_value')]
available_handshape += [hs for hs in Handshape.objects.filter(
machine_value__gt=1).order_by('name')]
context['available_handshape'] = available_handshape

context['available_locprim'] = [h for h in FieldChoice.objects.filter(
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(
field='Location', machine_value__gt=1).order_by('name')]
context['available_locprim'] = available_locprim

# data structures to store the query parameters in order to keep them in the form
context['query_parameters'] = json.dumps(self.query_parameters)
Expand Down
18 changes: 12 additions & 6 deletions signbank/dictionary/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def internal_batch_update_fields_for_gloss(gloss):

languages = gloss.lemma.dataset.translation_languages
gloss_prefix = str(gloss.id) + '_'
gloss_suffix = '_' + str(gloss.id)
internal_batch_fields = []
for language in languages:
gloss_lemma_field_name = BatchEditForm.gloss_lemma_field_prefix + gloss_prefix + language.language_code_2char
Expand All @@ -27,13 +26,9 @@ def internal_batch_update_fields_for_gloss(gloss):
internal_batch_fields.append(gloss_annotation_field_name)

for language in languages:
gloss_sense_field_name = self.gloss_sense_field_prefix + gloss_prefix + language.language_code_2char
gloss_sense_field_name = BatchEditForm.gloss_sense_field_prefix + gloss_prefix + language.language_code_2char
internal_batch_fields.append(gloss_sense_field_name)

internal_batch_fields.append('handedness' + gloss_suffix)
internal_batch_fields.append('domhndsh' + gloss_suffix)
internal_batch_fields.append('subhndsh' + gloss_suffix)

return internal_batch_fields


Expand All @@ -60,6 +55,17 @@ def get_sense_numbers(gloss):
return senses_mapping


def add_gloss_update_to_revision_history(user, gloss, field, oldvalue, newvalue):

revision = GlossRevision(old_value=oldvalue,
new_value=newvalue,
field_name=field,
gloss=gloss,
user=user,
time=datetime.now(tz=get_current_timezone()))
revision.save()


def batch_edit_update_gloss(request, glossid):
"""Update the gloss fields"""
if not request.user.is_authenticated:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
style="width:100%; overflow-y:scroll;">
<thead>
<tr>
<th></th>
<th style="width:250px;">{% trans "Gloss" %}</th>
<th style="width:500px;">{% trans "Fields" %}</th>
<th style="width:500px;">{% trans "Quick Toggles" %}</th>
Expand All @@ -281,6 +280,9 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
{% load underscore_to_space %}
{% for gloss in page_obj %}
<tr style="height:auto;">
<td>
<table>
<tr>
<td>{% if gloss.get_image_path %}
{% url 'dictionary:protected_media' '' as protected_media_url %}
<div class="thumbnail_container">
Expand All @@ -297,8 +299,7 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
</div>
{% endif %}
</td>
<td>
<table>
</tr>
<tr>
<td>
<a href="{{PREFIX_URL}}/dictionary/gloss/{{gloss.pk}}/">
Expand Down Expand Up @@ -392,7 +393,7 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
{% endfor %}
{% endfor %}
{% endwith %}
<tr>
<tr style="height:26px;">
<th>{% trans "Handedness" %}</th>
<td class="field_handedness" style="width:100px;">
<div class="handedness-cell"
Expand All @@ -401,7 +402,7 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
</td>
</tr>

<tr>
<tr style="height:26px;">
<th>{% trans "Strong Hand" %}</th>
<td class="field_domhndsh" style="width:100px;">
<div class="domhndsh-cell"
Expand All @@ -410,15 +411,15 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
</td>
</tr>

<tr>
<tr style="height:26px;">
<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>
<tr style="height:26px;">
<th>{% trans "Location" %}</th>
<td class="field_locprim" style="width:100px;">
<div class="locprim-cell"
Expand Down Expand Up @@ -540,7 +541,7 @@ <h4>{% trans "On initial view, prior to searching, recently added glosses are sh
{% endwith %}
</tr>
<tr>
<td colspan="2"></td>
<td></td>
<td>
<table class="table-responsive">
<tr>
Expand Down
7 changes: 4 additions & 3 deletions signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def update_gloss(request, glossid):
gloss.__setattr__(field,value)
gloss.save()

#If the value is not a Boolean, get the human readable value
# If the value is not a Boolean, get the human readable value
if not isinstance(value,bool):
# if we get to here, field is a valid field of Gloss
newvalue = value
Expand All @@ -1060,15 +1060,16 @@ def update_gloss(request, glossid):
category_value = 'phonology'

# the gloss has been updated, now prepare values for saving to GlossHistory and display in template
#This is because you cannot concat none to a string in py3
# This is because you cannot concat none to a string in py3
if original_value is None:
original_value = ''

# if choice_list is empty, the original_value is returned by the called function
# Remember this change for the history books
original_human_value = original_value.name if isinstance(original_value, FieldChoice) else original_value
if isinstance(value, bool) and field in settings.HANDSHAPE_ETYMOLOGY_FIELDS + settings.HANDEDNESS_ARTICULATION_FIELDS:
# store a boolean in the Revision History rather than a human value as for the template (e.g., 'letter' or 'number')
# store a boolean in the Revision History rather than a human value
# as for the template (e.g., 'letter' or 'number')
glossrevision_newvalue = value
else:
# this takes care of a problem with None not being allowed as a value in GlossRevision
Expand Down
21 changes: 20 additions & 1 deletion signbank/dictionary/update_glosses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from signbank.dictionary.models import *
from signbank.dictionary.forms import *

from signbank.dictionary.batch_edit import add_gloss_update_to_revision_history
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponseBadRequest, JsonResponse


Expand Down Expand Up @@ -244,15 +244,20 @@ def mapping_toggle_handedness(request, glossid, handedness):
handedness_machine_value = 0
new_handedness = empty_handedness

original_handedness = gloss.handedness.name if gloss.handedness else '-'
with atomic():
if not gloss.handedness:
gloss.handedness = new_handedness
elif gloss.handedness.machine_value != handedness_machine_value:
gloss.handedness = new_handedness
else:
gloss.handedness = empty_handedness
new_handedness = empty_handedness

gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'handedness', original_handedness, new_handedness.name)

result = dict()
result['glossid'] = str(gloss.id)
newvalue = gloss.handedness.name
Expand Down Expand Up @@ -292,15 +297,19 @@ def mapping_toggle_domhndsh(request, glossid, domhndsh):
domhndsh_machine_value = 0
new_domhndsh = empty_domhndsh

original_domhndsh = gloss.domhndsh.name if gloss.domhndsh else '-'
with atomic():
if not gloss.domhndsh:
gloss.domhndsh = new_domhndsh
elif gloss.domhndsh.machine_value != domhndsh_machine_value:
gloss.domhndsh = new_domhndsh
else:
gloss.domhndsh = empty_domhndsh
new_domhndsh = empty_domhndsh
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'domhndsh', original_domhndsh, new_domhndsh.name)

result = dict()
result['glossid'] = str(gloss.id)
newvalue = gloss.domhndsh.name
Expand Down Expand Up @@ -340,15 +349,20 @@ def mapping_toggle_subhndsh(request, glossid, subhndsh):
subhndsh_machine_value = 0
new_subhndsh = empty_subhndsh

original_subhndsh = gloss.subhndsh.name if gloss.subhndsh else '-'

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
new_subhndsh = empty_subhndsh
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'subhndsh', original_subhndsh, new_subhndsh.name)

result = dict()
result['glossid'] = str(gloss.id)
newvalue = gloss.subhndsh.name
Expand Down Expand Up @@ -388,15 +402,20 @@ def mapping_toggle_locprim(request, glossid, locprim):
locprim_machine_value = 0
new_locprim = empty_locprim

original_locprim = gloss.locprim.name if gloss.locprim else '-'

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
new_locprim = empty_locprim
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'locprim', original_locprim, new_locprim.name)

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

0 comments on commit 22efca9

Please sign in to comment.