diff --git a/signbank/dictionary/forms.py b/signbank/dictionary/forms.py index 4a0b6661..016630fa 100755 --- a/signbank/dictionary/forms.py +++ b/signbank/dictionary/forms.py @@ -230,7 +230,8 @@ class GlossSearchForm(forms.ModelForm): widget=forms.Select(attrs=ATTRS_FOR_BOOLEAN_FORMS)) hasmultiplesenses = forms.ChoiceField(label=_("Has Multiple Senses"), choices=[(0, '-')], widget=forms.Select(attrs=ATTRS_FOR_BOOLEAN_FORMS)) - + hasannotatedsentences = forms.ChoiceField(label=_("Has Annotated Sentences"), choices=[(0, '-')], + widget=forms.Select(attrs=ATTRS_FOR_BOOLEAN_FORMS)) relation = forms.CharField(label=_('Gloss of Related Sign'), widget=forms.TextInput(attrs=ATTRS_FOR_FORMS)) relationToForeignSign = forms.CharField(label=_('Gloss of Foreign Sign'), @@ -347,7 +348,7 @@ def __init__(self, *args, **kwargs): widget=forms.Select(attrs=ATTRS_FOR_FORMS)) for boolean_field in ['hasvideo', 'repeat', 'altern', 'isNew', 'inWeb', 'defspublished', 'excludeFromEcv', 'hasRelationToForeignSign', 'hasmultiplesenses', - 'hasothermedia', 'isablend', 'ispartofablend']: + 'hasothermedia', 'isablend', 'ispartofablend', 'hasannotatedsentences']: self.fields[boolean_field].choices = [('0', '-'), ('2', _('Yes')), ('3', _('No'))] for boolean_field in ['weakdrop', 'weakprop']: self.fields[boolean_field].choices = [(0, '-'), (1, _('Neutral')), (2, _('True')), (3, _('False'))] diff --git a/signbank/query_parameters.py b/signbank/query_parameters.py index dcd96727..ebfcff5d 100644 --- a/signbank/query_parameters.py +++ b/signbank/query_parameters.py @@ -72,7 +72,7 @@ def query_parameters_this_gloss(phonology_focus, phonology_matrix): # these mappings match the choices in the Gloss Search Form NEUTRALBOOLEANCHOICES = {'None': '1', 'True': '2', 'False': '3'} query_parameters[field_key] = NEUTRALBOOLEANCHOICES[field_value] - elif field_key in ['defspublished', 'hasmultiplesenses']: + elif field_key in ['defspublished', 'hasmultiplesenses', 'hasannotatedsentences']: # these mappings match the choices in the Gloss Search Form and get_queryset # some of these are legacy mappings YESNOCHOICES = {'None': '-', 'True': _('Yes'), 'False': _('No')} @@ -283,6 +283,14 @@ def convert_query_parameters_to_filter(query_parameters): 'gloss').annotate(Count('id')).filter(id__count=1)] query_list.append(Q(id__in=multiple_senses)) + elif get_key == 'hasannotatedsentences' and get_value: + glosses_with_annotated_sentences = [gsv['gloss'] for gsv in AnnotatedGloss.objects.values('gloss')] + val = get_value == 'yes' + if val: + query_list.append(Q(pk__in=glosses_with_annotated_sentences)) + else: + query_list.append(~Q(pk__in=glosses_with_annotated_sentences)) + elif get_key == 'negative' and get_value: sentences_with_negative_type = ExampleSentence.objects.filter(negative__exact=True) sentences_with_other_type = ExampleSentence.objects.filter(negative__exact=False) @@ -615,7 +623,7 @@ def pretty_print_query_values(dataset_languages,query_parameters): query_dict[key] = _('No') elif key in ['inWeb', 'isNew', 'excludeFromEcv', 'hasvideo', 'hasothermedia']: query_dict[key] = NULLBOOLEANCHOICES[query_parameters[key]] - elif key in ['defspublished', 'hasmultiplesenses', 'negative']: + elif key in ['defspublished', 'hasmultiplesenses', 'negative', 'hasannotatedsentences']: query_dict[key] = YESNOCHOICES[query_parameters[key]] elif key in ['hasRelation']: choices_for_category = [RELATION_ROLE_CHOICES[val] for val in query_parameters[key]] @@ -1127,6 +1135,14 @@ def queryset_glosssense_from_get(model, formclass, searchform, GET, qs): query_filter = gloss_prefix + 'id__in' qs = qs.filter(**{query_filter: multiple_senses}) continue + elif get_key in ['hasannotatedsentences']: + glosses_with_annotated_sentences = [gsv['gloss'] for gsv in AnnotatedGloss.objects.values('gloss')] + query_filter = gloss_prefix + 'id__in' + if get_value == '2': + qs = qs.filter(**{query_filter: glosses_with_annotated_sentences}) + else: + qs = qs.exclude(**{query_filter: glosses_with_annotated_sentences}) + continue elif get_key in ['hasothermedia']: pks_for_glosses_with_othermedia = [om.parent_gloss.pk for om in OtherMedia.objects.all()] query_filter = gloss_prefix + 'pk__in' diff --git a/signbank/settings/server_specific/default.py b/signbank/settings/server_specific/default.py index 409d42c5..de8d3540 100644 --- a/signbank/settings/server_specific/default.py +++ b/signbank/settings/server_specific/default.py @@ -145,7 +145,7 @@ FIELDS['publication'] = ['inWeb', 'isNew'] -FIELDS['properties'] = ['hasvideo', 'hasothermedia', 'hasmultiplesenses', +FIELDS['properties'] = ['hasvideo', 'hasothermedia', 'hasmultiplesenses', 'hasannotatedsentences', 'definitionRole', 'definitionContains', 'defspublished', 'createdBy', 'createdAfter', 'createdBefore', 'tags', 'excludeFromEcv']