I am creating an application that queries some data in an external relational database using collect.lead (trunk). The user can change the database connection settings in a custom tool of the Plone panel (I followed the example in the Aspeli Professional Plone Development development book). Thus, the database parameters are set in this way.
My configure.zcml product database installs a 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 is the registry not found at runtime? What am I doing wrong?
Thanks.
source share