-
-
Notifications
You must be signed in to change notification settings - Fork 183
/
search.py
49 lines (40 loc) · 2.14 KB
/
search.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
from Products.CMFPlone import PloneMessageFactory as _
from Products.CMFPlone.interfaces import ISearchSchema
from Products.CMFPlone.controlpanel.widgets import ReverseCheckBoxFieldWidget
from plone.app.registry.browser import controlpanel
from zope.component import queryUtility
from zope.schema.interfaces import IVocabularyFactory
class SearchControlPanelForm(controlpanel.RegistryEditForm):
id = "SearchControlPanel"
label = _(u"Search settings")
schema = ISearchSchema
def updateFields(self):
super(SearchControlPanelForm, self).updateFields()
self.fields['types_not_searched'].widgetFactory = \
ReverseCheckBoxFieldWidget
def updateWidgets(self):
super(SearchControlPanelForm, self).updateWidgets()
# Replace vocabulary for 'types_not_searched' with user friendly types
# to hide "bad" types in control panel.
vocab = self._friendly_types_vocabulary()
self.widgets['types_not_searched'].terms.terms = vocab(self.context)
self.widgets['types_not_searched'].update()
def applyChanges(self, data):
# We only get "friendly" types. Add "bad" types from current settings.
current_types = self.fields['types_not_searched'].field.get(
self.getContent())
all_vocab = queryUtility(IVocabularyFactory,
'plone.app.vocabularies.PortalTypes')
all_types = [t.value for t in all_vocab(self.context)]
friendly_vocab = self._friendly_types_vocabulary()
friendly_types = [t.value for t in friendly_vocab(self.context)]
submitted_types = data['types_not_searched'] or []
new_types = [t for t in all_types if t in submitted_types
or (t in current_types and t not in friendly_types)]
data['types_not_searched'] = tuple(new_types)
super(SearchControlPanelForm, self).applyChanges(data)
def _friendly_types_vocabulary(self):
return queryUtility(IVocabularyFactory,
'plone.app.vocabularies.ReallyUserFriendlyTypes')
class SearchControlPanel(controlpanel.ControlPanelFormWrapper):
form = SearchControlPanelForm