Denis Krienbühl on Software & Systems
  • Home
  • Posts
  • List all Plone Sites in a Zope Instance

List all Plone Sites in a Zope Instance

October 12, 2012

Calling plone_sites in the following code snippet will return a flat list of Plone Sites that are part of the current Zope Instance. As should be apparent it is possible for Plone Sites to be nested in other Plone Sites.

from OFS.interfaces import IApplication
from Products.CMFPlone.interfaces import IPloneSiteRoot
from zope.component.hooks import getSite

def zope_root():
    this = getSite()

    while not IApplication.providedBy(this):
        this = this.aq_inner.aq_parent

    return this

def plone_sites(root=None):
    root = root or zope_root()

    sites = []
    for id, item in root.items():
        if not IPloneSiteRoot.providedBy(item):
            continue

        sites.append(item)
        sites.extend(plone_sites(item))

return sites
I'm Denis Krienbühl, a Software & Systems-Engineer working at Seantis.
You can check my work on GitHub, contact me through E-Mail, or follow me on Twitter.