def getNearestSite(self): """return the nearest site, see IPhysicallyLocatable""" if ISite.providedBy(self.context): return self.context for parent in getParents(self.context): if ISite.providedBy(parent): return parent return self.getRoot()
def run(self, path="", do_delete=0): result = list() result.append("setOshaMetadataExtension") url_tool = getToolByName(self, "portal_url") portal = url_tool.getPortalObject() obj = self if path: try: obj = portal.restrictedTraverse(path) except: result.append("No object found for path %s" % path) return "\n".join(result) if do_delete and ISite.providedBy(obj): noLongerProvides(obj, ISite) del obj._components result.append("Deleted existing site manager") return "\n".join(result) # very special and dirty hack # We need to kill the existing SiteManager in the European Riskobservatory # folder, since it contains a reference to the no longer existing # IEroExtender if obj.id in ["riskobservatory"] and ISite.providedBy(obj): noLongerProvides(obj, ISite) del obj._components result.append("Deleted existing site manager") if not ISite.providedBy(obj): make_objectmanager_site(obj) result.append("Turned %s into a local site" % obj.id) sitemanager = obj.getSiteManager() sitemanager.registerAdapter(OshaMetadataExtender, (IATEvent,), IOrderableSchemaExtender, name="event-oshametadata") sitemanager.registerAdapter( OshaMetadataExtender, (IATNewsItem,), IOrderableSchemaExtender, name="news-oshametadata" ) sitemanager.registerAdapter( OshaMetadataExtender, (IATDocument,), IOrderableSchemaExtender, name="document-oshametadata" ) sitemanager.registerAdapter( OshaMetadataExtender, (Iwhoswho,), IOrderableSchemaExtender, name="document-oshametadata" ) sitemanager.registerAdapter( OshaMetadataExtender, (IPressRelease,), IOrderableSchemaExtender, name="pressrelease-oshametadata" ) result.append("Registered OshaMetadataExtender as adapter on %s" % obj.id) return "\n".join(result)
def disable_party(context): if ISite.providedBy(context): sm = context.getSiteManager() name = get_name_for_site(context) lookup = context.get("newsletter_lookup") if lookup is not None: sm.unregisterUtility(name=name, provided=ILocalNewsletterLookup)
def _maybePlacefullyAuthenticate(self, request, ob): if not IUnauthenticatedPrincipal.providedBy(request.principal): # We've already got an authenticated user. There's nothing to do. # Note that beforeTraversal guarentees that user is not None. return if not ISite.providedBy(ob): # We won't find an authentication utility here, so give up. return sm = removeSecurityProxy(ob).getSiteManager() auth = sm.queryUtility(IAuthentication) if auth is None: # No auth utility here return # Try to authenticate against the auth utility principal = auth.authenticate(request) if principal is None: principal = auth.unauthenticatedPrincipal() if principal is None: # nothing to do here return request.setPrincipal(principal)
def update(self): super(PageTitle, self).update() context = self.context request = self.request self.titleSeparator = component.getUtility(ISEO).titleSeparator if not ISite.providedBy(context): self.notRoot = True site = getSite() tags = IHTMLTags(site, None) if tags is not None and tags.isAvailable() and tags.title: self.portal_title = tags.title else: self.portal_title = getMultiAdapter( (site, request), IBreadcrumb).name tags = IHTMLTags(context, None) if tags is not None and tags.isAvailable() and tags.title: if not tags.appendSiteTitle: self.notRoot = False self.title = tags.title else: self.title = getMultiAdapter( (context, request), IBreadcrumb).name
def readme_setup(tc): oc_setup.fresh_skin(tc) if not ISite.providedBy(tc.portal): enableLocalSiteHook(tc.portal) setSite(tc.portal) setHooks() setup_mock_geocoder()
def setupVarious(context): portal = context.getSite() if not ISite.providedBy(portal): enableSite(portal) setupLanguages(portal) clearPortlets(portal) setupNavigationPortlet(portal)
def setEROSchemaExtension(self, path=''): result = list() url_tool = getToolByName(self, 'portal_url') portal = url_tool.getPortalObject() obj = None if path: try: obj = portal.restrictedTraverse(path) except: # well, path must habe been wrong result.append("No object found for path %s" %path) if not obj: obj = self result.append("Performing actions on self (%s)" %obj.absolute_url()) if not ISite.providedBy(obj): make_objectmanager_site(obj) result.append("Turned %s into a local site" %obj.id) sitemanager = obj.getSiteManager() sitemanager.registerAdapter(factory=TaggingSchemaExtenderERO, name=u"osha.metadata.ero") result.append("Registered TaggingSchemaExtenderERO as adapter on %s" %obj.id) return "\n".join(result)
def registerUtility(id, factory, ifaces, container='system'): site = getSite() if not ISite.providedBy(site): raise RuntimeError(_("Can't create utility.")) sm = component.getSiteManager() if isinstance(container, basestring): if container: if container not in sm: folder = SiteManagementFolder() event.notify(ObjectCreatedEvent(folder)) sm[container] = folder container = sm[container] else: container = sm elif container is None: container = sm if id not in container: if callable(factory): utility = factory() else: utility = component.createObject(factory) event.notify(ObjectCreatedEvent(utility)) removeSecurityProxy(container)[id] = utility for iface, name in ifaces: sm.registerUtility(utility, iface, name) return container[id]
def sublocations(self): folder = self.folder for key in folder: yield folder[key] if ISite.providedBy(folder): yield folder.getSiteManager()
def setEROSchemaExtension(self, path=''): result = list() url_tool = getToolByName(self, 'portal_url') portal = url_tool.getPortalObject() obj = None if path: try: obj = portal.restrictedTraverse(path) except: # well, path must habe been wrong result.append("No object found for path %s" % path) if not obj: obj = self result.append("Performing actions on self (%s)" % obj.absolute_url()) if not ISite.providedBy(obj): make_objectmanager_site(obj) result.append("Turned %s into a local site" % obj.id) sitemanager = obj.getSiteManager() sitemanager.registerAdapter(factory=TaggingSchemaExtenderERO, name=u"osha.metadata.ero") result.append("Registered TaggingSchemaExtenderERO as adapter on %s" % obj.id) return "\n".join(result)
def bootStrapSubscriber(event): """The actual subscriber to the bootstrap IDataBaseOpenedEvent Boostrap a Zope3 instance given a database object This first checks if the root folder exists and has a site manager. If it exists, nothing else is changed. If no root folder exists, one is added. """ db, connection, root, root_folder = getInformationFromEvent(event) root_created = False if root_folder is None: root_created = True # ugh... we depend on the root folder implementation root_folder = rootFolder() root[ZopePublication.root_name] = root_folder if not ISite.providedBy(root_folder): site_manager = site.LocalSiteManager(root_folder) root_folder.setSiteManager(site_manager) transaction.commit() connection.close() zope.event.notify(interfaces.DatabaseOpenedWithRoot(db))
def enableFolder(folder): zope.event.notify(ChildSiteWillBeCreatedEvent(folder)) if not ISite.providedBy(folder): make_objectmanager_site(folder) # reindex so that the object_provides index is aware of our # new interface reindexObjectProvides(folder) zope.event.notify(ChildSiteCreatedEvent(folder))
def isAvailable(self): context = self.context if ISite.providedBy(context) or \ IUnremoveableContent.providedBy(context) or \ IRenameNotAllowed.providedBy(context): return False return super(DeleteContentAction, self).isAvailable()
def isAvailable(self): context = self.context if IPortalType.providedBy(context) or ISite.providedBy(context): annotation = IAnnotations(context, None) if annotation is not None: return True return False
def siteTree(self): """Cookie tree with only folders and the nearest site as root node. """ parent = self.context for parent in zapi.getParents(self.context): if ISite.providedBy(parent): break return self.folderTree(parent)
def __init__(self, content, default=None): while not IDraftContent.providedBy(content): content = content.__parent__ if ISite.providedBy(content) or content is None: self.isDraft = False return self.isDraft = True
def isSelected(self, strict=False): intids = self.intids context = self.context if ISite.providedBy(context): if self.id == intids.queryId(context): return True return False while context is not None and not ISite.providedBy(context): if self.id == intids.queryId(context): return True elif strict: return False context = getattr(context, '__parent__', None) return False
def test_enabling_child_site(self): self.subtyper.change_type( self.portal.site1, u'collective.lineage.childsite') res = self.catalog(object_provides=IChildSite.__identifier__) rids = [r.getRID() for r in res] rid = self.catalog.getrid('/plone/site1') self.assertIn(rid, rids) self.assertTrue(ISite.providedBy(self.portal.site1))
def update(self): if ISite.providedBy(self.context): self.fields = self.fields.omit('currentLocation') if ('fromRoot' not in self.request.form \ and getUtility(ISearchConfig).fromRoot): self.request.form['%swidgets.fromRoot'%self.prefix] = ['true'] super(SearchForm, self).update()
def enableSite(self, portal): """ Make the portal a Zope3 site and create a site manager. """ if not ISite.providedBy(portal): make_objectmanager_site(portal) # The following event is primarily useful for setting the site hooks # during test runs. notify(SiteManagerCreatedEvent(portal))
def findObjectsProviding(root): if ISite.providedBy(root): yield root values = getattr(root, "values", None) if callable(values): for subobj in values(): for match in findObjectsProviding(subobj): yield match
def update(self): super(SearchPortlet, self).update() context = self.context while IPagelet.providedBy(context): context = context.__parent__ self.isSite = ISite.providedBy(context) self.contextUrl = absoluteURL(context, self.request)
def ensure_site(context): """Ensure the given context implements ISite. The importance of this method is that it will ensure the given context is an ISite regardless of the Zope version (Zope 2.9 had a really hacked up SiteManager mechanism we have to account for). >>> from zope.app.component.interfaces import ISite, IPossibleSite >>> from OFS.Folder import Folder >>> if not IPossibleSite.implementedBy(Folder): ... from zope import interface ... from Products.Five.site.metaconfigure import (FiveSite, ... classSiteHook) ... classSiteHook(Folder, FiveSite) ... interface.classImplements(Folder, IPossibleSite) >>> om = Folder('foo') >>> ISite.providedBy(om) False >>> ensure_site(om) >>> ISite.providedBy(om) True """ if not IPossibleSite.providedBy(context): if hasattr(context, 'getPhysicalPath'): p = '/'.join(context.getPhysicalPath()) elif hasattr(context, 'getId'): p = context.getId() elif hasattr(context, 'id'): p = id else: p = str(context) raise TypeError('The object, "%s", is not an IPossibleSite' % p) if not ISite.providedBy(context): enableLocalSiteHook(context) setSite(context) if not ISite.providedBy(context): raise TypeError('Somehow trying to configure "%s" as an ISite ' 'has failed' % '/'.join(context.getPhysicalPath()))
def disable_old_parties(newsletter): """ remove old named utilities based on path """ if ISite.providedBy(newsletter): sm = newsletter.getSiteManager() name = get_name_for_site_old(newsletter) lookup = newsletter.get("newsletter_lookup") if lookup is not None: sm.unregisterUtility(name=name, provided=ILocalNewsletterLookup)
def recursiveEsxVimSubscriber(obj): """distibution of esx_vim event """ if ISite.providedBy(obj): sitem = obj.getSiteManager() smList = list(sitem.getAllUtilitiesRegisteredFor(IAdmUtilEsxVim)) for utilObj in smList: if IAdmUtilEsxVim.providedBy(utilObj): globalEsxVimUtility.subscribeToEsxVim(utilObj)
def addSiteManager(self): """Convert a possible site to a site >>> from zope.app.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, 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: >>> 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 ISite.providedBy(self.context): raise zapi.UserError('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 enable_local_site(obj): enableSite(obj, iface=IObjectManagerSite) for parent in aq_chain(obj)[1:]: if ISite.providedBy(parent): p_sm = parent.getSiteManager() bases = (p_sm,) + p_sm.__bases__ break else: bases = (base,) components = PersistentComponents() components.__bases__ = bases obj.setSiteManager(components)
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IZipFileTransportUtility): sm.registerUtility(ZipFileTransportUtility('zipfiletransport'), IZipFileTransportUtility)
def disableLocalSiteHook(obj): """Remove __before_traverse__ hook for Local Site """ # We want the original object, not stuff in between, and no acquisition obj = aq_base(obj) if not ISite.providedBy(obj): raise TypeError, 'Must provide ISite' unregisterBeforeTraverse(obj, HOOK_NAME) if hasattr(obj, HOOK_NAME): delattr(obj, HOOK_NAME) directlyProvides(obj, directlyProvidedBy(obj) - ISite)
def next(self): obj = self.context while obj is not None: obj = aq_parent(aq_inner(obj)) if ISite.providedBy(obj): return obj.getSiteManager() # In Zope 3.1+, returning None here is understood by # getNextSiteManager as that our next site manager is the # global one. If we returned the global one, it would be # understood as a lookup error. Yeah, it's weird, tell me # about it. return None
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IContentLicensingUtility): sm.registerUtility(ContentLicensingUtility('contentlicensing'), IContentLicensingUtility)
def enable_local_site(obj): enableSite(obj, iface=IObjectManagerSite) for parent in aq_chain(obj)[1:]: if ISite.providedBy(parent): p_sm = parent.getSiteManager() bases = (p_sm, ) + p_sm.__bases__ break else: bases = (base, ) components = PersistentComponents() components.__bases__ = bases obj.setSiteManager(components)
def recursiveCronSubscriber(obj): """distibution of cron event """ if ISite.providedBy(obj): sitem = obj.getSiteManager() smList = list(sitem.getAllUtilitiesRegisteredFor(IAdmUtilCron)) for utilObj in smList: if IAdmUtilCron.providedBy(utilObj) : globalCronUtility.subscribeToCron(utilObj) if IContainer.providedBy(obj): for (dummy_name, subObject) in obj.items(): recursiveCronSubscriber(subObject)
def get_site(): """ Find the next Site if we're not "on" a site already. """ site = context = getSite() # rewritten from old seletz's code with try/except-pdb. I hope this is how it should work [naro] # ...hm it does not.. do we really need context from request ? # request = getattr(site, 'REQUEST', None) # if request is not None: # request = site.REQUEST # context = get_context_from_request(request) if ISite.providedBy(context): return context return site
def findObjectsProviding(root): if ISite.providedBy(root): yield root try: if len(getParents(root)) > 3: raise StopIteration() except TypeError: raise StopIteration() values = getattr(root, 'values', None) if callable(values): for subobj in values(): for match in findObjectsProviding(subobj): yield match
def siteManagerAdapter(ob): """An adapter * -> ISiteManager. This is registered in place of the one in Zope 3 so that we lookup using acquisition instead of ILocation. """ current = ob while True: if ISite.providedBy(current): return current.getSiteManager() current = getattr(current, '__parent__', aq_parent(aq_inner(current))) if current is None: # It does not support acquisition or has no parent, so we # return the global site return getGlobalSiteManager()
def enable_party(context): """ Make this container a local site and add all the needed tools, if they're not there yet. """ if not ISite.providedBy(context): make_objectmanager_site(context) sm = context.getSiteManager() name = get_name_for_site(context) add_tools(context) lookup = context.get("newsletter_lookup") interface.directlyProvides(lookup, ILocalNewsletterLookup) sm.registerUtility(lookup, name=name, provided=ILocalNewsletterLookup)
def crumbs(self): objects = [] for obj in ( [self.context] + list(zope.traversing.api.getParents(self.context)) ): if INotFound.providedBy(obj): obj = obj.getObject() objects.append(obj) if ISite.providedBy(obj): break objects.reverse() for object in objects: info = zope.component.getMultiAdapter((object, self.request), IBreadcrumb) yield {'name': info.name, 'url': info.url, 'activeURL': info.activeURL}
def run(self, path=''): result = list() url_tool = getToolByName(self, 'portal_url') portal = url_tool.getPortalObject() obj = self if path: try: obj = portal.restrictedTraverse(path) except: result.append("No object found for path %s" % path) return "\n".join(result) if not ISite.providedBy(obj): make_objectmanager_site(obj) result.append("Turned %s into a local site" % obj.id) sitemanager = obj.getSiteManager() sitemanager.registerAdapter( LinkListExtender, (IATEvent, ), IOrderableSchemaExtender, name='event-linklist', ) sitemanager.registerAdapter( LinkListExtender, (IRALink, ), IOrderableSchemaExtender, name='ralink-linklist', ) sitemanager.registerAdapter( LinkListExtender, (ICaseStudy, ), IOrderableSchemaExtender, name='casestudy-linklist', ) result.append("Registered LinkListExtender as adapter on %s" % obj.id) return "\n".join(result)
def test_local_site(self): dancefloor = ATFolder("dancefloor") self.failUnless(not ISite.providedBy(dancefloor)) make_objectmanager_site(dancefloor) self.failUnless(ISite.providedBy(dancefloor))
def run(self, path='', do_delete=0): result = list() result.append('setOshaMetadataExtension') url_tool = getToolByName(self, 'portal_url') portal = url_tool.getPortalObject() obj = self if path: try: obj = portal.restrictedTraverse(path) except: result.append("No object found for path %s" % path) return "\n".join(result) if do_delete and ISite.providedBy(obj): noLongerProvides(obj, ISite) del obj._components result.append('Deleted existing site manager') return "\n".join(result) # very special and dirty hack # We need to kill the existing SiteManager in the European Riskobservatory # folder, since it contains a reference to the no longer existing # IEroExtender if obj.id in [ 'riskobservatory', ] and ISite.providedBy(obj): noLongerProvides(obj, ISite) del obj._components result.append('Deleted existing site manager') if not ISite.providedBy(obj): make_objectmanager_site(obj) result.append("Turned %s into a local site" % obj.id) sitemanager = obj.getSiteManager() sitemanager.registerAdapter( OshaMetadataExtender, (IATEvent, ), IOrderableSchemaExtender, name='event-oshametadata', ) sitemanager.registerAdapter( OshaMetadataExtender, (IATNewsItem, ), IOrderableSchemaExtender, name='news-oshametadata', ) sitemanager.registerAdapter( OshaMetadataExtender, (IATDocument, ), IOrderableSchemaExtender, name='document-oshametadata', ) sitemanager.registerAdapter( OshaMetadataExtender, (Iwhoswho, ), IOrderableSchemaExtender, name='document-oshametadata', ) sitemanager.registerAdapter( OshaMetadataExtender, (IPressRelease, ), IOrderableSchemaExtender, name='pressrelease-oshametadata', ) result.append("Registered OshaMetadataExtender as adapter on %s" % obj.id) return "\n".join(result)
def isSite(self): return ISite.providedBy(self.context)