我正在遵循a tutorial关于操作dexterity内容对象。它解释了如何创建对象。
from zope.component import createObject
context = createObject('example.type')但我不确定该用什么来代替example.type。我尝试过使用IProduct、degu.product.IProduct和degu.Product。但它们都会引发一个ComponentLookupError。
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/daniel/.buildout/eggs/zope.component-3.9.5-py2.6.egg/zope/component/_api.py", line 220, in createObject
return getUtility(IFactory, __factory_name, context)(*args, **kwargs)
File "/home/daniel/.buildout/eggs/zope.component-3.9.5-py2.6.egg/zope/component/_api.py", line 169, in getUtility
raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass zope.component.interfaces.IFactory>, 'degu.commerce.product.IProduct')发布于 2013-03-03 19:41:16
您需要使用在Dexterity FTI registration中使用的相同名称。
您可以验证在portal_types工具中注册了哪些名称:
from Products.CMFCore.utils import getToolByName
typestool = getToolByName(context, 'portal_types')
print typestool.listContentTypes()或者在浏览器中访问ZMI中的portal_types工具并查看那里的类型列表;它们在该工具中被列为typeid (Type Title)。如果没有列出您的类型,请确保您首先正确注册了您的类型。
请注意,要使其正常工作,您需要正确设置本地组件管理器。通常,这会自动发生,但如果您使用的是bin/instance run脚本或bin/instance debug,则不会发生这种情况。在这种情况下,您需要手动执行此操作:
from zope.app.component.hooks import setSite
from Testing.makerequest import makerequest
app = makerequest(app)
site = app[site_id]
setSite(site)您可能还希望设置当前用户:
from AccessControl.SecurityManagement import newSecurityManager
user = app.acl_users.getUser('admin').__of__(site.acl_users)
newSecurityManager(None, user)https://stackoverflow.com/questions/15182063
复制相似问题