1

私は器用さのコンテンツオブジェクトの操作についてのチュートリアルに従っています。オブジェクトの作成方法について説明します。

from zope.component import createObject
context = createObject('example.type')

しかし、代わりに何を置くべきかわかりませんexample.typeIProduct、、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')
4

1 に答える 1

4

DexterityFTI登録で使用したのと同じ名前を使用する必要があります。

portal_typesツールに登録されている名前を確認できます。

from Products.CMFCore.utils import getToolByName

typestool = getToolByName(context, 'portal_types')
print typestool.listContentTypes()

またはportal_types、ブラウザのZMIのツールにアクセスして、そこにあるタイプのリストを確認します。それらは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)
于 2013-03-03T11:41:16.463 に答える