我正在構建一個應用程序,該應用程序使用collective.lead(trunk)查詢外部關係數據庫中的某些數據。用戶可以在自定義的Plone控制面板工具中修改數據庫連接設置(我遵循Aspeli的專業Plone開發手冊中的示例)。以這種方式查詢數據庫設置。在啓動時查詢註冊表時ComponentLookupError
我的產品的基本configure.zcml中建立數據庫的工具:
<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有:
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,
)
這就提出了在運行時ComponentLookupError例外:
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"
/>
爲什麼不在運行時找到註冊表?我究竟做錯了什麼?
謝謝。
謝謝。這是最乾淨的解決方案。 – zedr 2011-06-14 16:35:15