-
Notifications
You must be signed in to change notification settings - Fork 7
/
interfaces.py
281 lines (234 loc) · 9.73 KB
/
interfaces.py
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# -*- coding: utf-8 -*-
from collective.collectionfilter import _
from collective.collectionfilter import utils
from plone.api.portal import get_registry_record as getrec
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.app.z3cform.widget import SelectFieldWidget
from plone.autoform.directives import widget
from zope import schema
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
try:
from plone.formwidget.geolocation.vocabularies import default_map_layer
from plone.formwidget.geolocation.vocabularies import default_map_layers
HAS_GEOLOCATION = True
except ImportError:
HAS_GEOLOCATION = False
def pattern_options():
options = {
"basePath": utils.target_collection_base_path,
"recentlyUsed": True,
"selectableTypes": utils.target_collection_types,
}
return options
class ICollectionish(Interface):
"Adapts object similar to ICollection if has contentlisting tile, or is a collection"
class ICollectionFilterBaseSchema(Interface):
header = schema.TextLine(
title=_("label_header", default=u"Filter title"),
description=_("help_header", u"Title of the rendered filter."),
required=False,
)
target_collection = schema.Choice(
title=_(u"label_target_collection", default=u"Alternative Target Collection"),
description=_(
u"help_target_collection",
default=u"We use the current context as collection. As an alternative you can select a different "
u"collection as source for the filter items "
u"and where the filter is applied.",
),
required=False,
vocabulary="plone.app.vocabularies.Catalog",
)
widget(
"target_collection", RelatedItemsFieldWidget, pattern_options=pattern_options()
)
view_name = schema.TextLine(
title=_("label_view_name", default=u"Result listing view name"),
description=_(
"help_view_name",
default=u"Optional view name, if the result listing should be"
u" rendered with a special view. Can be used to direct the request"
u" to a tile.",
),
required=False,
default=None,
)
content_selector = schema.TextLine(
title=_("label_content_selector", default=u"Content Selector"),
description=_(
"help_content_selector",
default=u"If your tile or collection has a special class or id for ajax replacement use it here."
u" Selector will need to work for unthemed view and current page.",
),
required=False,
)
class ICollectionFilterSchema(ICollectionFilterBaseSchema):
"""Schema for the filter."""
group_by = schema.Choice(
title=_("label_groupby", u"Group by"),
description=_(
"help_groupby", u"Select the criteria to group the collection results by."
),
required=True,
vocabulary="collective.collectionfilter.GroupByCriteria",
)
show_count = schema.Bool(
title=_(u"label_show_count", default=u"Show count"),
description=_(
u"help_show_count", default=u"Show the result count for each filter group."
),
default=False,
required=False,
)
cache_enabled = schema.Bool(
title=_(u"label_cache_enabled", default=u"Enable Cache"),
description=_(
u"help_cache_enabled",
default=u"Enable caching of filter items. The cache is cleared as"
u" soon as the database has any changes.",
),
default=True,
required=False,
)
filter_type = schema.Choice(
title=_("label_filter_type", u"Filter Type"),
description=_(
"help_filter_type",
u"Select if single or multiple criterias can be selected and if all (and) or any (or) of the selected criterias must be met." # noqa
u"Some index types like ``FieldIndex`` (e.g. Type index) only support the any (or) criteria when set to multiple criterias and ignore, if all (and) is set.", # noqa
),
required=True,
vocabulary="collective.collectionfilter.FilterType",
)
input_type = schema.Choice(
title=_("label_input_type", u"Input Type"),
description=_(
"help_input_type",
u"Select how the UI of the collection filter should be rendered. "
u"Wether as links, as checkboxes and radiobuttons or checkboxes and dropdowns.", # noqa
),
required=True,
vocabulary="collective.collectionfilter.InputType",
)
reverse = schema.Bool(
title=_(u"label_reverse", default=u"Reverse sort filter"),
description=_(
u"help_reverse",
default=u"Reverse the sorting of th list of filter options.",
),
default=False,
required=False,
)
narrow_down = schema.Bool(
title=_(u"label_narrow_down", default=u"Narrow down filter options"),
description=_(
u"help_narrow_down",
default=u"Narrow down the filter options when a filter of this group is applied." # noqa
u" Only options, which are available in the result set will then be displayed." # noqa
u" Other filter groups can still narrow down this one, though.",
), # noqa
default=False,
required=False,
)
hide_if_empty = schema.Bool(
title=_(u"label_hide_if_empty", default=u"Hide if empty"),
description=_(
u"help_hide_if_empty",
default=u"Don't display if there is 1 or no options without selecting a filter yet.",
),
default=False,
required=False,
)
# list_scaling = schema.Choice(
# title=_('label_list_scaling', u'List scaling'),
# description=_(
# 'help_list_scaling',
# u'Scale list by count. If a scaling is selected, a the list '
# u'appears as tagcloud.'
# ),
# required=True,
# vocabulary='collective.collectionfilter.ListScaling',
# )
class ICollectionSearchSchema(ICollectionFilterBaseSchema):
"""Schema for the search filter."""
class ICollectionFilterResultListSort(ICollectionFilterBaseSchema):
"""Schema for the result list sorting."""
sort_on = schema.Tuple(
title=_("label_sort_on", u"Enabled sort indexes"),
description=_("help_sort_on", u"Select the indexes which can be sorted on."),
value_type=schema.Choice(
title=u"Index",
vocabulary="collective.collectionfilter.SortOnIndexes",
),
required=True,
)
# NB needed as InAndOut breaks tiles in 5.0
widget("sort_on", SelectFieldWidget, pattern_options=dict(orderable=True))
input_type = schema.Choice(
title=_("label_input_type", u"Input Type"),
description=_(
"help_input_type",
u"Select how the UI of the collection filter should be rendered. "
u"Wether as links, as checkboxes and radiobuttons or checkboxes and dropdowns.", # noqa
),
required=True,
vocabulary="collective.collectionfilter.InputType",
)
class IGroupByCriteria(Interface):
"""Interface for the GroupByCriteria utility.
groupby provides a datastructure like this::
GROUPBY_CRITERIA = {
'Subject': {
'index': 'Subject', # Index for querying.
'metadata': 'Subject', # Metadata name for fast access.
'display_modifier': _, # Function for modifying list items
# for display. Gets the item passed
'css_modifier': None, # Change css class of filter item
'index_modifier': None, # Change index values before querying
'value_blacklist': None # Exclude index values from display
'sort_key_function': None, # sort key function. defaults to a lower-cased title. # noqa
},
}
"""
class IGroupByModifier(Interface):
"""Adapter interface for modifying the groupby criteria data structure,
after it has been initially created.
"""
class ICollectionFilterBrowserLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""
if HAS_GEOLOCATION:
def map_layer_default():
return getrec(name="geolocation.default_map_layer", default=default_map_layer)
def map_layers_default():
return getrec(name="geolocation.map_layers", default=default_map_layers)
class ICollectionMapsSchema(ICollectionFilterBaseSchema):
"""schema for maps filtering"""
narrow_down = schema.Bool(
title=_(u"label_narrow_down_results", default=u"Narrow down result"),
description=_(
u"help_narrow_down_results",
default=u"Narrow down the result after zooming/moving the map.",
),
default=False,
required=False,
)
default_map_layer = schema.Choice(
title=_(u"default_map_layer", u"Default map layer"),
description=_(
u"help_default_map_layer", default=u"Set the default map layer"
),
required=False,
defaultFactory=map_layer_default,
vocabulary="plone.formwidget.geolocation.vocabularies.map_layers",
)
map_layers = schema.List(
title=_(u"label_map_layers", u"Map Layers"),
description=_(u"help_map_layers", default=u"Set the available map layers"),
required=False,
defaultFactory=map_layers_default,
missing_value=[],
value_type=schema.Choice(
vocabulary="plone.formwidget.geolocation.vocabularies.map_layers"
),
) # noqa: E501