I'm building an app that queries some data in an external relational database, using collective.lead (trunk). The user can modify the database connection settings in a custom Plone control panel tool (I followed the example in Aspeli's Professional Plone Development book). The database settings are queried in this way.
My product's base configure.zcml sets up an utility for the database:
<include package="plone.app.registry" />
<include package="collective.lead" />
<i18n:registerTranslations directory="locales" />
<utility
provides="collective.lead.interfaces.IDatabase"
factory=".dbsettings.CalculatorDatabase"
name="test.calc.db"
/>
dbsettings.py has:
from zope.component import getUtility
from plone.registry.interfaces import IRegistry
class CalculatorDatabase(Database):
@property
def _url(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(IDatabaseSettings)
return URL(
drivername=settings.drivername,
username=settings.username,
password=settings.password,
host=settings.hostname,
port=settings.port,
database=settings.database,
)
This raises a ComponentLookupError exception at runtime:
File "/home/zope/envs/test-web/src/test.calc/test/calc/dbsettings.py", line 38, in _url
registry = getUtility(IRegistry)
File "/home/zope/envs/test-web/eggs/zope.component-3.7.1-py2.6.egg/zope/component/_api.py", line 171, in getUtility
raise ComponentLookupError(interface, name)
zope.configuration.config.ConfigurationExecutionError: <class 'zope.component.interfaces.ComponentLookupError'>: (<InterfaceClass plone.registry.interfaces.IRegistry>, '')
in:
File "/home/zope/envs/test-web/src/test.calc/test/calc/configure.zcml", line 26.2-30.6
<utility
provides="collective.lead.interfaces.IDatabase"
factory=".dbsettings.CalculatorDatabase"
name="test.calc.db"
/>
Why isn't the Registry found at runtime? What am I doing wrong?
Thanks.