specialised_fields.py
4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from django import forms
from semantics.models import (
Frame, SemanticRole, RoleAttribute,
PredefinedSelectionalPreference,
Synset,
RelationalSelectionalPreference,
SelectionalPreferenceRelation,
)
from .generic_fields import (
RadiosLayoutField,
SingleRegexFilter,
ModelChoiceFilter,
ComboFilter,
)
from .query_managers import (
QueryManager,
)
class ArgumentFilter(ComboFilter):
def __init__(self):
super().__init__(
label='Argument',
inner_class=Frame,
outer_lookup='subentries__schema_hooks__argument_connections__argument__frame__in',
fields=[
ModelChoiceFilter(
label='Rola',
empty_label='Rola',
queryset=SemanticRole.objects.all(),
key='role',
entry_lookup=None,
object_lookup='argument__role__role',
),
ModelChoiceFilter(
label='Atrybut roli',
empty_label='Atrybut roli',
queryset=RoleAttribute.objects.all(),
key='attribute',
entry_lookup=None,
object_lookup='argument__role__attribute',
),
],
negation_field=True,
)
class PredefinedPreferenceFilter(ComboFilter):
def __init__(self):
super().__init__(
label='Predefiniowane',
inner_class=Frame,
outer_lookup='subentries__schema_hooks__argument_connections__argument__frame__in',
fields=[
ModelChoiceFilter(
label='Predefiniowane',
empty_label='Predefiniowane',
queryset=PredefinedSelectionalPreference.objects.all(),
key='key',
entry_lookup=None,
object_lookup='argument__predefined',
),
],
negation_field=True,
)
class RelationalPreferenceFilter(ComboFilter):
def __init__(self):
super().__init__(
label='Relacja',
inner_class=Frame,
outer_lookup='subentries__schema_hooks__argument_connections__argument__frame__in',
fields=[
ModelChoiceFilter(
label='Relacja',
empty_label='Relacja',
queryset=SelectionalPreferenceRelation.objects.all(),
key='key',
entry_lookup=None,
object_lookup='argument__relations__relation',
),
ModelChoiceFilter(
label='Do: rola',
empty_label='Do: rola',
queryset=SemanticRole.objects.all(),
key='role',
entry_lookup=None,
object_lookup='argument__relations__to__role__role',
),
ModelChoiceFilter(
label='Do: atrybut',
empty_label='Do: atrybut',
queryset=RoleAttribute.objects.all(),
key='attribute',
entry_lookup=None,
object_lookup='argument__relations__to__role__attribute',
),
]
)
# TODO add a ‘text_rep’ field to the Synset object
class SynsetPreferenceFilter(ComboFilter):
def __init__(self):
super().__init__(
label='Synset',
inner_class=Frame,
outer_lookup='subentries__schema_hooks__argument_connections__argument__frame__in',
fields=[
SingleRegexFilter(
label='Synset',
entry_lookup=None,
object_lookup='argument__synsets__lexical_units__text_rep',
),
]
)
# TODO implementation without internal QueryManager subclass?
class PhraseoFilter(forms.ChoiceField, RadiosLayoutField):
class PhraseoQueryManager(QueryManager):
def __init__(self):
super().__init__(None, None)
# Assumes this filter is used on either Entry or Schema and uses the
# fact that both have the same related name for Subentry
def _make_queries(self, _, value, op):
if value == '1':
return [Q(subentries__schemata__phraseologic=True)]
if value == '0':
return [~Q(subentries__schemata__phraseologic=True)]
return []
def __init__(self):
super().__init__(
label='Frazeologia',
choices=(('2', 'dowolnie'), ('1', 'zawiera'), ('0', 'nie zawiera')),
initial='2',
required=False,
)
self.query_manager = PhraseoFilter.PhraseoQueryManager()