首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试创建新的dexterity对象时使用ComponentLookupError

尝试创建新的dexterity对象时使用ComponentLookupError
EN

Stack Overflow用户
提问于 2013-03-03 11:13:51
回答 1查看 278关注 0票数 1

我正在遵循a tutorial关于操作dexterity内容对象。它解释了如何创建对象。

代码语言:javascript
复制
from zope.component import createObject
context = createObject('example.type')

但我不确定该用什么来代替example.type。我尝试过使用IProductdegu.product.IProductdegu.Product。但它们都会引发一个ComponentLookupError。

代码语言:javascript
复制
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')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-03 19:41:16

您需要使用在Dexterity FTI registration中使用的相同名称。

您可以验证在portal_types工具中注册了哪些名称:

代码语言:javascript
复制
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,则不会发生这种情况。在这种情况下,您需要手动执行此操作:

代码语言:javascript
复制
from zope.app.component.hooks import setSite
from Testing.makerequest import makerequest

app = makerequest(app)
site = app[site_id]
setSite(site)

您可能还希望设置当前用户:

代码语言:javascript
复制
from AccessControl.SecurityManagement import newSecurityManager

user = app.acl_users.getUser('admin').__of__(site.acl_users)
newSecurityManager(None, user)
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15182063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档