def test_customize_component(self): from zope import interface from zope.app.component.site import LocalSiteManager from naaya.component.interfaces import ICustomize class MyClassCustomizer(object): interface.implements(ICustomize) def __init__(self, target): self.target = target def customize(self, site_manager, name): site_manager.registerUtility(MyClass(color='red'), name=name) self.bundle_names.append('test-bundle') test_bundle = bundles.get('test-bundle') test_bundle.registerUtility(MyClass(color='green'), name='tomato') test_bundle.registerAdapter(MyClassCustomizer, [ITestUtil], ICustomize) site_manager = LocalSiteManager(None) site_manager.__bases__ = (test_bundle, ) bundles.customize_utility(site_manager, ITestUtil, 'tomato') util = site_manager.getUtility(ITestUtil, name='tomato') self.assertEqual(util.color, 'red')
def test_customize_component(self): from zope import interface from zope.app.component.site import LocalSiteManager from naaya.component.interfaces import ICustomize class MyClassCustomizer(object): interface.implements(ICustomize) def __init__(self, target): self.target = target def customize(self, site_manager, name): site_manager.registerUtility(MyClass(color='red'), name=name) self.bundle_names.append('test-bundle') test_bundle = bundles.get('test-bundle') test_bundle.registerUtility(MyClass(color='green'), name='tomato') test_bundle.registerAdapter(MyClassCustomizer, [ITestUtil], ICustomize) site_manager = LocalSiteManager(None) site_manager.__bases__ = (test_bundle,) bundles.customize_utility(site_manager, ITestUtil, 'tomato') util = site_manager.getUtility(ITestUtil, name='tomato') self.assertEqual(util.color, 'red')
def addSiteHandler(site, event): sitemanager = LocalSiteManager(site) # LocalSiteManager creates the 'default' folder in its __init__. # It's not needed anymore in new versions of Zope 3, therefore we # remove it del sitemanager['default'] site.setSiteManager(sitemanager)
def addSiteManager(self): """Convert a possible site to a site >>> from zope.traversing.interfaces import IContainmentRoot >>> from zope.interface import implements >>> class PossibleSite(object): ... implements(IContainmentRoot) ... def setSiteManager(self, sm): ... from zope.interface import directlyProvides ... directlyProvides(self, zope.component.interfaces.ISite) >>> folder = PossibleSite() >>> from zope.publisher.browser import TestRequest >>> request = TestRequest() Now we'll make our folder a site: >>> MakeSite(folder, request).addSiteManager() Now verify that we have a site: >>> zope.component.interfaces.ISite.providedBy(folder) 1 Note that we've also redirected the request: >>> request.response.getStatus() 302 >>> request.response.getHeader('location') '++etc++site/@@SelectedManagementView.html' If we try to do it again, we'll fail: >>> MakeSite(folder, request).addSiteManager() Traceback (most recent call last): ... UserError: This is already a site """ if zope.component.interfaces.ISite.providedBy(self.context): raise UserError(_(u'This is already a site')) # We don't want to store security proxies (we can't, # actually), so we have to remove proxies here before passing # the context to the SiteManager. bare = removeSecurityProxy(self.context) sm = LocalSiteManager(bare) self.context.setSiteManager(sm) self.request.response.redirect( "++etc++site/@@SelectedManagementView.html")
def setSiteManagerWhenAdded(site, event): """ event handler to register """ if ISlave.providedBy(event.object): site.setSiteManager(LocalSiteManager(site)) try: old_site = hooks.getSite() hooks.setSite(site) ensureUtility(event.object, IIntIds, '', IntIds, name='IntIds', copy_to_zlog=False, asObject=True) madeUtilityICatalog = ensureUtility(\ event.object, ICatalog, '', Catalog, name='Catalog', copy_to_zlog=False, asObject=True) oid_index = TextIndex(interface=ISearchableText, field_name='getSearchableOid', field_callable=True) madeUtilityICatalog['oid_index'] = oid_index madeAdmUtilSupervisor = ensureUtility(\ event.object, IAdmUtilSupervisor, 'AdmUtilSupervisor', AdmUtilSupervisor, name='AdmUtilSupervisor', copy_to_zlog=False, asObject=True) madeAdmUtilSupervisor.status2Master = u"will be a slave" finally: hooks.setSite(old_site)
def setUp(test): functional.FunctionalTestSetup().setUp() root = functional.getRootFolder() portal = Portal() event.notify(ObjectCreatedEvent(portal)) root['portal'] = portal sm = LocalSiteManager(portal) portal.setSiteManager(sm) setSite(portal) sm = portal.getSiteManager() portal['ids'] = IntIds() sm.registerUtility(portal['ids'], IIntIds) portal['catalog'] = Catalog() sm.registerUtility(portal['catalog'], ICatalog) authconfiglet = sm.getUtility(IAuthenticationConfiglet) authconfiglet.installUtility() sm.getUtility(IAuthentication)._caching = False
def configure_site(site, event): log.info(u"Making %s a site manager..." % site) sm = LocalSiteManager(site) site.setSiteManager(sm) log.info(u'Creating registrations utility...') sm['registrations'] = Registrations() sm.registerUtility(sm['registrations'], IRegistrations) log.info(u"Creating authentication systems...") sm['session_data'] = RAMSessionDataContainer() sm.registerUtility(sm['session_data'], ISessionDataContainer) sm['authentication'] = PluggableAuthentication() sm.registerUtility(sm['authentication'], IAuthentication) sm['authentication']['session_credentials'] = SessionCredentialsPlugin() sm['authentication']['members'] = PrincipalFolder() sm['authentication'].authenticatorPlugins = ('members',) sm['authentication'].credentialsPlugins = ('session_credentials',) log.info(u"Creating indexing system...") sm['intids'] = IntIds() sm.registerUtility(sm['intids'], IIntIds) sm['catalog'] = Catalog() sm.registerUtility(sm['catalog'], ICatalog) sm['catalog']['searchableText'] = TextIndex(field_name="getSearchableText", interface=ISearchableText, field_callable=True) sm['catalog']['name'] = FieldIndex("name", IPortalContent, False) sm['catalog']['tags'] = KeywordIndex('tags', ILearningEntry, False)
def setSiteManagerWhenAdded(site, event): site.setSiteManager(LocalSiteManager(site))
def __call__(self, data): portal = self.context # create site manager try: sm = portal.getSiteManager() except: sm = None if sm is None: sm = LocalSiteManager(portal) portal.setSiteManager(sm) setSite(portal) if 'system' not in sm: system = SiteManagementFolder() event.notify(ObjectCreatedEvent(system)) sm['system'] = system else: system = sm['system'] # IIntId utility if 'ids' not in system: ids = component.createObject('zope.app.intid.IntIds') event.notify(ObjectCreatedEvent(ids)) system['ids'] = ids else: system['ids'].__init__() ids = system['ids'] sm.registerUtility(system['ids'], IIntIds) ids.register(portal) # Principal Annotations if 'principalannotations' not in system: pa = component.createObject('zope.app.PrincipalAnnotationUtility') event.notify(ObjectCreatedEvent(pa)) system['principalannotations'] = pa sm.registerUtility(pa, IPrincipalAnnotationUtility) # session data container configlet = sm.getUtility(IConfiglet, 'system.session') configlet.sessiontype = 'ram' # set password password = sm.getUtility(IConfiglet, 'principals.password') password.passwordManager = 'MD5' # set site timezone fomratter = sm.getUtility(IConfiglet, 'system.formatter') fomratter.timezone = u'UTC' # set portal access to open manager = IPrincipalPermissionManager(portal) everyone = sm.queryUtility(IEveryoneGroup) if everyone is not None: manager.grantPermissionToPrincipal( 'zojax.AccessPortal', everyone.id) authenticated = sm.queryUtility(IAuthenticatedGroup) if authenticated is not None: manager.unsetPermissionForPrincipal( 'zojax.AccessPortal', authenticated.id) # setup default role roles = sm.getUtility(IPortalRoles) if 'site.member' not in roles: role = PortalRole(title = u'Site Member') event.notify(ObjectCreatedEvent(role)) roles['site.member'] = role roleId = role.id sm.getUtility(IDefaultPortalRole).roles = [role.id] roleperm = IRolePermissionManager(portal) for permId in ('zojax.PersonalContent', 'zojax.PersonalSpace', 'zojax.forum.addMessage', 'zojax.forum.addTopic', 'zojax.SubmitBlogPost', 'zojax.SubmitDocuments', 'zojax.forum.SubmitTopic', 'zojax.SubmitPhoto', 'zojax.contenttype.SubmitNewsItem',): roleperm.grantPermissionToRole(permId, roleId) # install catalog sm.getUtility(IConfiglet, 'system.catalog').install() # install workspaces portal.workspaces = ('overview', 'people', 'news', 'documents') event.notify(ObjectModifiedEvent(portal)) setSite(None)