Skip to content
Snippets Groups Projects
Commit 3fccd580 authored by Kasia Krasnowska's avatar Kasia Krasnowska
Browse files

filter forms updates + fixes

parent 7d782110
No related branches found
No related tags found
No related merge requests found
...@@ -100,7 +100,7 @@ def or_button(button_label, add_button_id): ...@@ -100,7 +100,7 @@ def or_button(button_label, add_button_id):
def other_button(button_label, add_button_id): def other_button(button_label, add_button_id):
return bootstrap.StrictButton('+ {} ({})'.format(_('Inny'), button_label), css_class='other-button btn-xs btn-warning', data_add_id=add_button_id) return bootstrap.StrictButton('+ {} ({})'.format(_('Inny'), button_label), css_class='other-button btn-xs btn-warning', data_add_id=add_button_id)
def and_or_form_creator(button_label, button_id, field=None, data_add=None, add_other=False, *args, **kwargs): def and_or_form_creator(button_label, button_id, field=None, data_add=None, add_other=False, help=None, tooltip=None, *args, **kwargs):
add_button = None add_button = None
data_add = 'switch' if data_add is None else data_add data_add = 'switch' if data_add is None else data_add
if field is not None: if field is not None:
...@@ -115,6 +115,11 @@ def and_or_form_creator(button_label, button_id, field=None, data_add=None, add_ ...@@ -115,6 +115,11 @@ def and_or_form_creator(button_label, button_id, field=None, data_add=None, add_
] ]
if add_other: if add_other:
ret.insert(-1, other_button(button_label, button_id)) ret.insert(-1, other_button(button_label, button_id))
if help:
help_tooltip = ''
if tooltip:
help_tooltip = ' <span data-toggle="tooltip" data-placement="bottom" title="{}"><img src="/static/common/img/info.svg" alt="info" width="12" height="12"/></span>'.format(tooltip)
ret.insert(-1, layout.HTML('<small class="form-text text-muted">{}{}</small>'.format(help, help_tooltip)))
return ret return ret
class EntryForm(QueryForm): class EntryForm(QueryForm):
...@@ -138,17 +143,26 @@ class EntryForm(QueryForm): ...@@ -138,17 +143,26 @@ class EntryForm(QueryForm):
schema_components = [ schema_components = [
self.make_field('num_schemata'), self.make_field('num_schemata'),
] + \ ] + \
and_or_form_creator(_('Schemat'), 'add-schema-0', data_add='schema', add_other=True) + \ and_or_form_creator(_('Schemat'), 'add-schema-0', data_add='schema', add_other=True, help=_('Schemat(y) występujące w haśle')) + \
and_or_form_creator(_('Pozycja'), 'add-position-0', data_add='position', add_other=True,
help=_('Pozycja/e występujące w haśle'),
tooltip=_('Pozycje mogą występować w różnych schematach. Aby ograniczyć filtrowanie do występowania wymaganych pozycji w obrębie jednego schematu, proszę użyć filtru POZYCJA wewnątrz filtra SCHEMAT powyżej.')
) + \
and_or_form_creator(_('Fraza'), 'add-phrase-0', field=self.make_field('phrase_type'), data_prefix='phrase_',
help=_('Fraza/y występujące w haśle'),
tooltip=_('Frazy mogą występować w różnych schematach i na różnych pozycjach. Aby ograniczyć filtrowanie do występowania wymaganych fraz w obrębie jednej pozycji, proszę użyć filtru POZYCJA powyżej lub wewnątrz filtra SCHEMAT.')
) + \
[ [
self.make_field('filter_schemata'), self.make_field('filter_schemata'),
] ]
#and_or_form_creator(_('Fraza'), 'add-phrase-0', field=self.make_field('phrase_type'), data_prefix='phrase_') + \
frame_components = [ frame_components = [
self.make_field('num_frames'), self.make_field('num_frames'),
] + \ ] + \
and_or_form_creator(_('Rama'), 'add-frame-0', data_add='frame', add_other=True) + \ and_or_form_creator(_('Rama'), 'add-frame-0', data_add='frame', add_other=True, help=_('Rama/y występujące w haśle')) + \
and_or_form_creator(_('Argument'), 'add-argument-0', data_add='argument', help=_('Argument(y) występujące w haśle')) + \
[ [
self.make_field('filter_frames'), self.make_field('filter_frames'),
] ]
...@@ -181,6 +195,7 @@ class EntryForm(QueryForm): ...@@ -181,6 +195,7 @@ class EntryForm(QueryForm):
label ='Status', label ='Status',
queryset=Status.objects.all().order_by('-priority'), queryset=Status.objects.all().order_by('-priority'),
key = 'key', key = 'key',
human_values=polish_strings.STATUS(),
lookup='status', lookup='status',
) )
num_schemata = RangeFilter( num_schemata = RangeFilter(
...@@ -193,7 +208,8 @@ class EntryForm(QueryForm): ...@@ -193,7 +208,8 @@ class EntryForm(QueryForm):
) )
phrase_type = PhraseTypeFilter( phrase_type = PhraseTypeFilter(
queryset=PhraseTypeModel.objects.filter(main_phrase_types__positions__schemata__isnull=False).distinct(), queryset=PhraseTypeModel.objects.filter(main_phrase_types__positions__schemata__isnull=False).distinct(),
help_text=_('Typ frazy występujący w haśle.')) #help_text=_('Typ frazy występujący w haśle.'),
)
filter_schemata = SwitchField(_('Ukryj niepasujące schematy')) filter_schemata = SwitchField(_('Ukryj niepasujące schematy'))
filter_frames = SwitchField(_('Ukryj niepasujące ramy')) filter_frames = SwitchField(_('Ukryj niepasujące ramy'))
...@@ -201,10 +217,14 @@ class EntryForm(QueryForm): ...@@ -201,10 +217,14 @@ class EntryForm(QueryForm):
def get_child_form_prefix(child_form): def get_child_form_prefix(child_form):
if child_form.model_class == Schema: if child_form.model_class == Schema:
return 'subentries__schemata__in' return 'subentries__schemata__in'
if child_form.model_class == Position:
return 'subentries__schemata__positions__in'
if child_form.model_class == PhraseType: if child_form.model_class == PhraseType:
return 'subentries__schemata__positions__phrase_types__in' return 'subentries__schemata__positions__phrase_types__in'
if child_form.model_class == Frame: if child_form.model_class == Frame:
return 'subentries__schema_hooks__argument_connections__argument__frame__in' return 'subentries__schema_hooks__argument_connections__argument__frame__in'
if child_form.model_class == Argument:
return 'subentries__schema_hooks__argument_connections__argument__in'
raise KeyError(type(child_form)) raise KeyError(type(child_form))
...@@ -314,7 +334,6 @@ class SchemaFormFactory(FormFactory): ...@@ -314,7 +334,6 @@ class SchemaFormFactory(FormFactory):
key='key', key='key',
human_values=polish_strings.SCHEMA_OPINION(), human_values=polish_strings.SCHEMA_OPINION(),
lookup='opinion', lookup='opinion',
#initial=SchemaOpinion.objects.filter(key__in=('col', 'vul')),
), ),
None, None,
), ),
...@@ -400,7 +419,7 @@ class SchemaFormFactory(FormFactory): ...@@ -400,7 +419,7 @@ class SchemaFormFactory(FormFactory):
#), #),
( (
None, None, None, None,
lambda n, cls: and_or_form_creator(_('Pozycja'), 'add-position-{}'.format(n), data_add='position', add_other=True), lambda n, cls: and_or_form_creator(_('Pozycja'), 'add-position-{}'.format(n), data_add='position', add_other=True, help=_('Pozycja/e występujące w schemacie')),
), ),
) )
...@@ -449,10 +468,19 @@ class PositionFormFactory(FormFactory): ...@@ -449,10 +468,19 @@ class PositionFormFactory(FormFactory):
lookup='pred_control', lookup='pred_control',
), None, ), None,
), ),
(
'num_phrases',
lambda: RangeFilter(
label=_('Liczba fraz'),
lookup='phrases_count',
),
None,
),
( (
'phrase_type', 'phrase_type',
lambda: PhraseTypeFilter(help_text=_('Typ frazy występujący na pozycji.')), #lambda: PhraseTypeFilter(help_text=_('Typ frazy występujący na pozycji.')),
lambda n, cls: and_or_form_creator(_('Fraza'), 'add-phrase-{}'.format(n), field=cls.make_field(FormFactory.unique_name('phrase_type', n)), data_prefix='phrase_'), lambda: PhraseTypeFilter(),
lambda n, cls: and_or_form_creator(_('Fraza'), 'add-phrase-{}'.format(n), field=cls.make_field(FormFactory.unique_name('phrase_type', n)), data_prefix='phrase_', help=_('Fraza/y występujące na pozycji')),
), ),
) )
...@@ -629,6 +657,8 @@ class ArgumentFormFactory(FormFactory): ...@@ -629,6 +657,8 @@ class ArgumentFormFactory(FormFactory):
return 'relations__in' return 'relations__in'
if child_form.model_class == Synset: if child_form.model_class == Synset:
return 'synsets__in' return 'synsets__in'
if child_form.model_class == PhraseType:
return 'argument_connections__schema_connections__phrase_type__in'
raise KeyError(type(child_form)) raise KeyError(type(child_form))
......
...@@ -35,7 +35,7 @@ from .forms import ( ...@@ -35,7 +35,7 @@ from .forms import (
SynsetPreferenceFormFactory, SynsetPreferenceFormFactory,
) )
from .polish_strings import SCHEMA_OPINION, FRAME_OPINION, EXAMPLE_SOURCE, EXAMPLE_OPINION, RELATION from .polish_strings import STATUS, SCHEMA_OPINION, FRAME_OPINION, EXAMPLE_SOURCE, EXAMPLE_OPINION, RELATION
from .phrase_descriptions.descriptions import position_prop_description from .phrase_descriptions.descriptions import position_prop_description
...@@ -350,12 +350,13 @@ def get_entries(request): ...@@ -350,12 +350,13 @@ def get_entries(request):
if order_dir == 'desc': if order_dir == 'desc':
order_field = '-' + order_field order_field = '-' + order_field
entries = entries.order_by(order_field) entries = entries.order_by(order_field)
status_names = STATUS()
entries_list = list(entries.values('id', 'name', 'status__key')) entries_list = list(entries.values('id', 'name', 'status__key'))
result = { result = {
'draw' : scroller_params['draw'], 'draw' : scroller_params['draw'],
'recordsTotal': total, 'recordsTotal': total,
'recordsFiltered': filtered, 'recordsFiltered': filtered,
'data': entries_list[i:j], 'data': [{'id' : e['id'], 'name' : e['name'], 'status__key' : status_names[e['status__key']]} for e in entries_list[i:j]],
} }
return JsonResponse(result) return JsonResponse(result)
return JsonResponse({}) return JsonResponse({})
...@@ -574,6 +575,70 @@ def get_examples(entry): ...@@ -574,6 +575,70 @@ def get_examples(entry):
}) })
return sorted(examples, key=lambda x: x['sentence']) return sorted(examples, key=lambda x: x['sentence'])
# [[POS1], [POS2, POS3]]
# =>
# [
# [
# (<SchemaForm>, [], [('position', 'or', [[POS1]])])
# ],
# [
# (<SchemaForm>, [], [('position', 'or', [[POS2]])]),
# (<SchemaForm>, [], [('position', 'or', [[POS3]])])
# ]
# ]
def position_forms2schema_forms(forms):
dummy_schema_form = make_form('schema', data={})
# validate the dummy to ensure access to cleaned_data
assert(dummy_schema_form.is_valid())
return [
[(dummy_schema_form, [], [('position', 'or', [[posf]])]) for posf in posfs]
for posfs in forms
]
# [[ATR1, ATR2], [ATR3]]
# =>
# [
# [
# (<SchemaForm>, [], [('position', 'or', [[(<PositionForm>, [], [('switch', 'or', [[ATR]])])]])]),
# (<SchemaForm>, [], [('position', 'or', [[(<PositionForm>, [], [('switch', 'or', [[ATR]])])]])])
# ],
# [
# (<SchemaForm>, [], [('position', 'or', [[(<PositionForm>, [], [('switch', 'or', [[ATR]])])]])])
# ]
# ]
def phrase_forms2schema_forms(forms):
dummy_schema_form = make_form('schema', data={})
dummy_position_form = make_form('position', data={})
# validate the dummies to ensure access to cleaned_data
assert(dummy_schema_form.is_valid())
assert(dummy_position_form.is_valid())
return [
[(dummy_schema_form, [], [('position', 'or', [[(dummy_position_form, [], [('switch', 'or', [[phrf]])])]])]) for phrf in phrfs]
for phrfs in forms
]
# [[ARG1, ARG2], [ARG3]]
# =>
# [
# [
# (<FrameForm>, [], [('argument', 'or', [[ARG1]])]),
# (<FrameForm>, [], [('argument', 'or', [[ARG2]])])
# ],
# [
# (<FrameForm>, [], [('argument', 'or', [[ARG3]])])
# ]
# ]
def argument_forms2frame_forms(forms):
dummy_frame_form = make_form('frame', data={})
# validate the dummy to ensure access to cleaned_data
assert(dummy_frame_form.is_valid())
return [
[(dummy_frame_form, [], [('argument', 'or', [[argf]])]) for argf in argfs]
for argfs in forms
]
#TODO test (*) changes #TODO test (*) changes
@ajax_required @ajax_required
...@@ -596,23 +661,43 @@ def get_entry(request): ...@@ -596,23 +661,43 @@ def get_entry(request):
filter_schemata, filter_frames = entry_form.cleaned_data['filter_schemata'], entry_form.cleaned_data['filter_frames'] filter_schemata, filter_frames = entry_form.cleaned_data['filter_schemata'], entry_form.cleaned_data['filter_frames']
if filter_schemata: if filter_schemata:
schema_forms = [frms[2] for frms in children_forms if frms[0] == 'schema'] schema_forms = []
assert (len(schema_forms) <= 1) # e.g. entry has schema that satisfies X & entry has schema that satisfies Y
if schema_forms: # => filtering schemata shows only schemata that contributed to the match
schema_forms = schema_forms[0] # => leave schemata that satisfies X or satisfy Y
schema_forms1 = [frms[2] for frms in children_forms if frms[0] == 'schema']
assert (len(schema_forms1) <= 1)
if schema_forms1:
schema_forms = schema_forms1[0]
# e.g. entry has position that satisfies X & entry has position that satisfies Y
# => entry has schema that has position that satisfies X
# & entry has schema that has position that satisfies Y
# => leave schemata that have position that satisfies X or have position that satisfies Y
position_forms = [frms[2] for frms in children_forms if frms[0] == 'position']
assert (len(position_forms) <= 1)
if position_forms:
position_forms = position_forms[0]
schema_forms += position_forms2schema_forms(position_forms)
phrase_forms = [frms[2] for frms in children_forms if frms[0] == 'switch'] phrase_forms = [frms[2] for frms in children_forms if frms[0] == 'switch']
assert (len(phrase_forms) <= 1) assert (len(phrase_forms) <= 1)
if phrase_forms: if phrase_forms:
phrase_forms = phrase_forms[0] phrase_forms = phrase_forms[0]
print('=====================', phrase_forms) schema_forms += phrase_forms2schema_forms(phrase_forms)
filter_schemata = schema_forms or phrase_forms filter_schemata = len(schema_forms) > 0
if filter_frames: if filter_frames:
frame_forms = [frms[2] for frms in children_forms if frms[0] == 'frame'] frame_forms = []
assert (len(frame_forms) <= 1) frame_forms1 = [frms[2] for frms in children_forms if frms[0] == 'frame']
if frame_forms: assert (len(frame_forms1) <= 1)
frame_forms = frame_forms[0] if frame_forms1:
else: frame_forms = frame_forms1[0]
filter_frames = False argument_forms = [frms[2] for frms in children_forms if frms[0] == 'argument']
assert (len(argument_forms) <= 1)
if argument_forms:
argument_forms = argument_forms[0]
frame_forms += argument_forms2frame_forms(argument_forms)
filter_frames = len(frame_forms) > 0
local_schema_form = None local_schema_form = None
if 'schema_form' in request.session: if 'schema_form' in request.session:
...@@ -633,7 +718,7 @@ def get_entry(request): ...@@ -633,7 +718,7 @@ def get_entry(request):
schemata = [] schemata = []
schema_objects = subentry.schemata.all() schema_objects = subentry.schemata.all()
# filter out schemata by schema properties # filter out schemata by schema properties
if filter_schemata and schema_forms: if filter_schemata:
schema_objects = get_filtered_objects2(schema_forms, schema_objects) schema_objects = get_filtered_objects2(schema_forms, schema_objects)
if local_schema_form: if local_schema_form:
schema_objects = get_filtered_objects(local_schema_form, schema_objects) schema_objects = get_filtered_objects(local_schema_form, schema_objects)
......
No preview for this file type
This diff is collapsed.
...@@ -8,7 +8,7 @@ msgid "" ...@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-06-30 10:15+0200\n" "POT-Creation-Date: 2021-07-07 12:20+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
...@@ -180,27 +180,27 @@ msgstr ": sort column in descending order" ...@@ -180,27 +180,27 @@ msgstr ": sort column in descending order"
msgid "Formularz filtrowania zawiera błędy." msgid "Formularz filtrowania zawiera błędy."
msgstr "The filtering form contains errors." msgstr "The filtering form contains errors."
#: entries/static/entries/js/forms.js:46 entries/static/entries/js/forms.js:108 #: entries/static/entries/js/forms.js:49 entries/static/entries/js/forms.js:111
msgid "nie" msgid "nie"
msgstr "not" msgstr "not"
#: entries/static/entries/js/forms.js:83 #: entries/static/entries/js/forms.js:86
msgid "i" msgid "i"
msgstr "and" msgstr "and"
#: entries/static/entries/js/forms.js:83 #: entries/static/entries/js/forms.js:86
msgid "lub" msgid "lub"
msgstr "or" msgstr "or"
#: entries/static/entries/js/forms.js:142 #: entries/static/entries/js/forms.js:145
msgid "zwiń" msgid "zwiń"
msgstr "collapse" msgstr "collapse"
#: entries/static/entries/js/forms.js:147 #: entries/static/entries/js/forms.js:150
msgid "rozwiń" msgid "rozwiń"
msgstr "expand" msgstr "expand"
#: entries/static/entries/js/forms.js:160 #: entries/static/entries/js/forms.js:163
msgid "" msgid ""
"Łączenie negacji elementu z operatorem ‹inny› na jednym poziomie formularza " "Łączenie negacji elementu z operatorem ‹inny› na jednym poziomie formularza "
"jest niemożliwe." "jest niemożliwe."
...@@ -208,33 +208,33 @@ msgstr "" ...@@ -208,33 +208,33 @@ msgstr ""
"Mixing element negation with ‹other› operator on the same level is not " "Mixing element negation with ‹other› operator on the same level is not "
"possible." "possible."
#: entries/static/entries/js/forms.js:177 #: entries/static/entries/js/forms.js:180
msgid "Kliknij, aby wyłączyć negację tego atrybutu." msgid "Kliknij, aby wyłączyć negację tego atrybutu."
msgstr "Click to switch off negation of this attribute." msgstr "Click to switch off negation of this attribute."
#: entries/static/entries/js/forms.js:179 #: entries/static/entries/js/forms.js:182
msgid "Kliknij, aby zanegować ten atrybut." msgid "Kliknij, aby zanegować ten atrybut."
msgstr "Click to negate this attribute." msgstr "Click to negate this attribute."
#: entries/static/entries/js/forms.js:203 #: entries/static/entries/js/forms.js:206
msgid "" msgid ""
"Łączenie operatorów ‹lub› i ‹inny› na jednym poziomie formularza jest " "Łączenie operatorów ‹lub› i ‹inny› na jednym poziomie formularza jest "
"niemożliwe." "niemożliwe."
msgstr "Mixing ‹or› and ‹other› operators on the same level is not possible." msgstr "Mixing ‹or› and ‹other› operators on the same level is not possible."
#: entries/static/entries/js/forms.js:210 #: entries/static/entries/js/forms.js:213
msgid "Proszę najpierw dodać element," msgid "Proszę najpierw dodać element,"
msgstr "First add an element" msgstr "First add an element"
#: entries/static/entries/js/forms.js:210 #: entries/static/entries/js/forms.js:213
msgid "aby użyć operatora ‹lub›" msgid "aby użyć operatora ‹lub›"
msgstr "in order to use ‹or› operator" msgstr "in order to use ‹or› operator"
#: entries/static/entries/js/forms.js:210 #: entries/static/entries/js/forms.js:213
msgid "aby użyć operatora ‹inny›" msgid "aby użyć operatora ‹inny›"
msgstr "in order to use ‹other› operator" msgstr "in order to use ‹other› operator"
#: entries/static/entries/js/forms.js:214 #: entries/static/entries/js/forms.js:217
msgid "" msgid ""
"Łączenie operatora ‹inny› z negacją elementu na jednym poziomie formularza " "Łączenie operatora ‹inny› z negacją elementu na jednym poziomie formularza "
"jest niemożliwe." "jest niemożliwe."
...@@ -242,24 +242,24 @@ msgstr "" ...@@ -242,24 +242,24 @@ msgstr ""
"Mixing ‹other› operator with element negation on the same level is not " "Mixing ‹other› operator with element negation on the same level is not "
"possible." "possible."
#: entries/static/entries/js/forms.js:218 #: entries/static/entries/js/forms.js:221
msgid "LUB" msgid "LUB"
msgstr "OR" msgstr "OR"
#: entries/static/entries/js/forms.js:218 #: entries/static/entries/js/forms.js:221
msgid "INNY" msgid "INNY"
msgstr "OTHER" msgstr "OTHER"
#: entries/static/entries/js/forms.js:218 #: entries/static/entries/js/forms.js:221
msgid "Usuń" msgid "Usuń"
msgstr "Remove" msgstr "Remove"
#: entries/static/entries/js/forms.js:229 #: entries/static/entries/js/forms.js:232
msgid "Wykonanie zapytania z operatorem ‹inny› może trwać zauważalnie dłużej." msgid "Wykonanie zapytania z operatorem ‹inny› może trwać zauważalnie dłużej."
msgstr "" msgstr ""
"Execution of a query using the ‹other› operator can take considerably longer." "Execution of a query using the ‹other› operator can take considerably longer."
#: entries/static/entries/js/forms.js:322 #: entries/static/entries/js/forms.js:325
msgid "" msgid ""
"Dodanie elementu jest niemożliwe: osiągnięto maksymalny poziom zagnieżdżenia." "Dodanie elementu jest niemożliwe: osiągnięto maksymalny poziom zagnieżdżenia."
msgstr "Can’t add an element: maximum depth reached." msgstr "Can’t add an element: maximum depth reached."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment