Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SearchControlPanelAdapter implementation.
- Loading branch information
Showing
11 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Plone Controlpanel | ||
================== | ||
|
||
All control panel related settings are stored in plone.app.registry and | ||
can be looked up like this:: | ||
|
||
>>> from zope.component import getUtility | ||
>>> from plone.registry.interfaces import IRegistry | ||
>>> registry = getUtility(IRegistry) | ||
|
||
>>> from Products.CMFPlone.interfaces import ISearchSchema | ||
>>> search_settings = registry.forInterface(ISearchSchema) | ||
|
||
>>> site_settings.enable_livesearch | ||
True | ||
|
||
If you want to change the settings, just change the attribute:: | ||
|
||
>>> search_settings.enable_livesearch = False | ||
|
||
|
||
Search Control Panel | ||
-------------------- | ||
|
||
>>> from plone.app.controlpanel.interfaces import ISearchSchema | ||
>>> site_settings = registry.forInterface(ISearchSchema) | ||
|
||
>>> site_settings.enable_livesearch = True | ||
>>> site_settings.types_not_searched = ('Discussion Item', 'Folder') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:five="http://namespaces.zope.org/five" | ||
xmlns:browser="http://namespaces.zope.org/browser"> | ||
|
||
<adapter factory=".search.SearchControlPanelAdapter" /> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from zope.site.hooks import getSite | ||
from Products.CMFPlone.interfaces.siteroot import IPloneSiteRoot | ||
from zope.component import adapts | ||
from zope.interface import implements | ||
from Products.CMFPlone.interfaces import ISearchSchema | ||
from Products.CMFCore.utils import getToolByName | ||
from zope.component import getUtility | ||
from plone.registry.interfaces import IRegistry | ||
|
||
|
||
class SearchControlPanelAdapter(object): | ||
|
||
adapts(IPloneSiteRoot) | ||
implements(ISearchSchema) | ||
|
||
def __init__(self, context): | ||
self.portal = getSite() | ||
self.jstool = getToolByName(context, 'portal_javascripts') | ||
registry = getUtility(IRegistry) | ||
self.search_settings = registry.forInterface(ISearchSchema) | ||
|
||
def get_enable_livesearch(self): | ||
return self.search_settings.enable_livesearch | ||
|
||
def set_enable_livesearch(self, value): | ||
if value: | ||
self.search_settings.enable_livesearch = True | ||
#self.jstool.getResource('livesearch.js').setEnabled(True) | ||
else: | ||
self.search_settings.enable_livesearch = False | ||
#self.jstool.getResource('livesearch.js').setEnabled(False) | ||
self.jstool.cookResources() | ||
|
||
enable_livesearch = property(get_enable_livesearch, set_enable_livesearch) | ||
|
||
def get_types_not_searched(self): | ||
return self.search_settings.types_not_searched | ||
|
||
def set_types_not_searched(self, value): | ||
self.search_settings.types_not_searched = value | ||
|
||
types_not_searched = property( | ||
get_types_not_searched, | ||
set_types_not_searched | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
67 changes: 67 additions & 0 deletions
67
Products/CMFPlone/controlpanel/tests/test_controlpanel_bbb_search_adapter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- coding: utf-8 -*- | ||
from Products.CMFPlone.interfaces import ISearchSchema | ||
from Products.CMFPlone.testing import \ | ||
PRODUCTS_CMFPLONE_INTEGRATION_TESTING | ||
from plone.app.testing import TEST_USER_ID, setRoles | ||
from plone.registry.interfaces import IRegistry | ||
from zope.component import getUtility | ||
from zope.component import getAdapter | ||
|
||
import unittest2 as unittest | ||
|
||
|
||
class SearchControlPanelAdapterTest(unittest.TestCase): | ||
|
||
layer = PRODUCTS_CMFPLONE_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) | ||
registry = getUtility(IRegistry) | ||
self.search_settings = registry.forInterface(ISearchSchema) | ||
|
||
def test_adapter_lookup(self): | ||
self.assertTrue(getAdapter(self.portal, ISearchSchema)) | ||
|
||
def test_get_enable_livesearch(self): | ||
self.assertEqual( | ||
getAdapter(self.portal, ISearchSchema).enable_livesearch, | ||
True | ||
) | ||
self.search_settings.enable_livesearch = False | ||
self.assertEquals( | ||
getAdapter(self.portal, ISearchSchema).enable_livesearch, | ||
False | ||
) | ||
|
||
def test_set_enable_livesearch(self): | ||
self.assertEquals( | ||
self.search_settings.enable_livesearch, | ||
True | ||
) | ||
getAdapter(self.portal, ISearchSchema).enable_livesearch = False | ||
self.assertEquals( | ||
self.search_settings.enable_livesearch, | ||
False | ||
) | ||
|
||
def test_get_types_not_searched(self): | ||
self.assertTrue( | ||
'Folder' not in | ||
getAdapter(self.portal, ISearchSchema).types_not_searched | ||
) | ||
self.search_settings.types_not_searched = ('Folder',) | ||
self.assertTrue( | ||
'Folder' in | ||
getAdapter(self.portal, ISearchSchema).types_not_searched | ||
) | ||
|
||
def test_set_types_not_searched(self): | ||
self.assertTrue( | ||
'Folder' not in self.search_settings.types_not_searched | ||
) | ||
getAdapter(self.portal, ISearchSchema).types_not_searched = ('Folder',) | ||
self.assertTrue( | ||
'Folder' in self.search_settings.types_not_searched | ||
) |
78 changes: 78 additions & 0 deletions
78
Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_search.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest2 as unittest | ||
|
||
from plone.testing.z2 import Browser | ||
from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD | ||
|
||
from zope.component import getUtility | ||
from plone.registry.interfaces import IRegistry | ||
from plone.registry import Registry | ||
from Products.CMFPlone.interfaces import ISearchSchema | ||
|
||
from zope.component import getMultiAdapter | ||
|
||
from Products.CMFCore.utils import getToolByName | ||
|
||
from plone.app.testing import TEST_USER_ID, setRoles | ||
|
||
from Products.CMFPlone.testing import \ | ||
PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING | ||
|
||
|
||
class SearchControlPanelFunctionalTest(unittest.TestCase): | ||
"""Test that changes in the search control panel are actually | ||
stored in the registry. | ||
""" | ||
|
||
layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.app = self.layer['app'] | ||
self.portal = self.layer['portal'] | ||
self.portal_url = self.portal.absolute_url() | ||
self.browser = Browser(self.app) | ||
self.browser.handleErrors = False | ||
self.browser.addHeader( | ||
'Authorization', | ||
'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) | ||
) | ||
|
||
def test_search_control_panel_link(self): | ||
self.browser.open( | ||
"%s/plone_control_panel" % self.portal_url) | ||
self.browser.getLink('Search').click() | ||
|
||
def test_search_control_panel_backlink(self): | ||
self.browser.open( | ||
"%s/@@search-controlpanel" % self.portal_url) | ||
self.assertTrue("Plone Configuration" in self.browser.contents) | ||
|
||
def test_search_control_panel_sidebar(self): | ||
self.browser.open( | ||
"%s/@@search-controlpanel" % self.portal_url) | ||
self.browser.getLink('Site Setup').click() | ||
self.assertEqual( | ||
self.browser.url, | ||
'http://nohost/plone/@@overview-controlpanel') | ||
|
||
def test_enable_livesearch(self): | ||
self.browser.open( | ||
"%s/@@search-controlpanel" % self.portal_url) | ||
self.browser.getControl('Enable LiveSearch').selected = True | ||
self.browser.getControl('Save').click() | ||
|
||
registry = getUtility(IRegistry) | ||
settings = registry.forInterface(ISearchSchema) | ||
self.assertEqual(settings.enable_livesearch, True) | ||
|
||
def test_types_not_searched(self): | ||
self.browser.open( | ||
"%s/@@search-controlpanel" % self.portal_url) | ||
self.browser.getControl( | ||
name='form.widgets.types_not_searched:list').value = ['Discussion Item', 'News Item'] | ||
self.browser.getControl('Save').click() | ||
|
||
registry = getUtility(IRegistry) | ||
settings = registry.forInterface(ISearchSchema) | ||
self.assertFalse('Discussion Item' in settings.types_not_searched) | ||
self.assertFalse('News Item Item' in settings.types_not_searched) |
34 changes: 34 additions & 0 deletions
34
Products/CMFPlone/controlpanel/tests/test_controlpanel_doctest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Functional Doctests for control panel. | ||
""" | ||
import doctest | ||
|
||
import unittest2 as unittest | ||
import pprint | ||
|
||
from plone.testing import layered | ||
|
||
from Products.CMFPlone.testing import \ | ||
PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING | ||
|
||
|
||
optionflags = ( | ||
doctest.ELLIPSIS | | ||
doctest.NORMALIZE_WHITESPACE | | ||
doctest.REPORT_ONLY_FIRST_FAILURE) | ||
normal_testfiles = [ | ||
'../README.rst', | ||
] | ||
|
||
|
||
def test_suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTests([ | ||
layered(doctest.DocFileSuite(test, | ||
optionflags=optionflags, | ||
globs={'pprint': pprint.pprint, | ||
} | ||
), | ||
layer=PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING) | ||
for test in normal_testfiles]) | ||
return suite |
File renamed without changes.
cf93738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TESTS PASSED
Mr.Roboto url : http://jenkins.plone.org/roboto/get_info?push=4f00a718ecd54085b423bc0c6c32b10d
plone-5.0-python-2.7 [SUCCESS]