plone/plone.api — comment on commit b8dd24fdf3f45876b2626d1281d80d209d088626
File:  line 0
By davisagli:

This can be improved in a few ways:

1. In order to avoid depending on zope.app.component the getSite import should be:

try:
from zope.component.hooks import getSite
except ImportError:
from zope.app.component.hooks import getSite

2. getSite returns the active component registry, not the Plone site. (It's different for KSS requests and in cases where a developer has set up a section-specific component registry.) Better use something like getToolByName(getSite(), 'portal_url').getPortalObject() or go up the acquisition chain of REQUEST['PUBLISHED'] until you find an IPloneSiteRoot or something like that.