diff --git a/signbank/dictionary/adminviews.py b/signbank/dictionary/adminviews.py index 74c91d33..7c91c463 100755 --- a/signbank/dictionary/adminviews.py +++ b/signbank/dictionary/adminviews.py @@ -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) diff --git a/signbank/dictionary/batch_edit.py b/signbank/dictionary/batch_edit.py index d130c8ab..e7f2ec7f 100644 --- a/signbank/dictionary/batch_edit.py +++ b/signbank/dictionary/batch_edit.py @@ -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 @@ -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 @@ -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: diff --git a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html index 11aaf658..6abef4c5 100644 --- a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html +++ b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html @@ -270,7 +270,6 @@

{% trans "On initial view, prior to searching, recently added glosses are sh style="width:100%; overflow-y:scroll;"> - {% trans "Gloss" %} {% trans "Fields" %} {% trans "Quick Toggles" %} @@ -281,6 +280,9 @@

{% trans "On initial view, prior to searching, recently added glosses are sh {% load underscore_to_space %} {% for gloss in page_obj %} + + + -
{% if gloss.get_image_path %} {% url 'dictionary:protected_media' '' as protected_media_url %}
@@ -297,8 +299,7 @@

{% trans "On initial view, prior to searching, recently added glosses are sh

{% endif %}
- + + - + - + - + - +
@@ -392,7 +393,7 @@

{% trans "On initial view, prior to searching, recently added glosses are sh {% endfor %} {% endfor %} {% endwith %} -

{% trans "Handedness" %}
{% trans "On initial view, prior to searching, recently added glosses are sh
{% trans "Strong Hand" %}
{% trans "On initial view, prior to searching, recently added glosses are sh
{% trans "Weak Hand" %}
{% trans "On initial view, prior to searching, recently added glosses are sh
{% trans "Location" %}
{% trans "On initial view, prior to searching, recently added glosses are sh {% endwith %}
diff --git a/signbank/dictionary/update.py b/signbank/dictionary/update.py index bbd1fdd6..374cdeb0 100755 --- a/signbank/dictionary/update.py +++ b/signbank/dictionary/update.py @@ -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 @@ -1060,7 +1060,7 @@ 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 = '' @@ -1068,7 +1068,8 @@ def update_gloss(request, glossid): # 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 diff --git a/signbank/dictionary/update_glosses.py b/signbank/dictionary/update_glosses.py index e057ca07..3f09cb39 100644 --- a/signbank/dictionary/update_glosses.py +++ b/signbank/dictionary/update_glosses.py @@ -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 @@ -244,6 +244,7 @@ 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 @@ -251,8 +252,12 @@ def mapping_toggle_handedness(request, glossid, handedness): 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 @@ -292,6 +297,7 @@ 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 @@ -299,8 +305,11 @@ def mapping_toggle_domhndsh(request, glossid, domhndsh): 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 @@ -340,6 +349,8 @@ 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 @@ -347,8 +358,11 @@ def mapping_toggle_subhndsh(request, glossid, subhndsh): 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 @@ -388,6 +402,8 @@ 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 @@ -395,8 +411,11 @@ def mapping_toggle_locprim(request, glossid, locprim): 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