我一直在尝试用灵巧的工具createContentInContainer
在我的plone站点中创建内容。在
我编写了一个在zopepy实例下运行的脚本,它完成了以下任务:
我知道我的方法非常幼稚,但我通过以下方式创建了到应用程序数据库的连接:
storage = FileStorage.FileStorage('.../var/filestorage/Data.fs')
db = DB(storage)
conn = db.open()
dbroot = conn.root()
我尝试通过以下方式创建内容:
^{pr2}$portal_type
以前设置为我的自定义内容类型。item
既是传递给内容接口的元组列表(这将抛出Could not adapt
TypeError),又是从接口继承的未注册适配器。在
类型的接口注册在profiles/defualt/types
中的mysite.Widget.xml
中,但脚本不断抛出:
Traceback (most recent call last):
File "./bin/zopepy", line 345, in <module>
execfile(__file__)
File "importdex.py", line 105, in <module>
createContentInContainer(dbroot['Application']['myapp']['existingfolder'], portal_type, checkConstraints=False, content=item)
File "env/mysite/eggs/plone.dexterity-1.0-py2.7.egg/plone/dexterity/utils.py", line 149, in createContentInContainer
content = createContent(portal_type, **kw)
File "env/mysite/eggs/plone.dexterity-1.0-py2.7.egg/plone/dexterity/utils.py", line 105, in createContent
fti = getUtility(IDexterityFTI, name=portal_type)
File "env/mysite/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 169, in getUtility
raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (<InterfaceClass plone.dexterity.interfaces.IDexterityFTI>, 'mysite.Widget')
正如我所提到的,我知道我的方法非常幼稚,我可能应该挨一巴掌。如果我以令人困惑的方式提出我的问题,我很抱歉。在
我的问题是:
createContentInContainer
吗?我操纵的连接是否足够,或者脚本是否需要在应用程序中运行以继承Dexterity/FTI需要的东西来完成我的要求?在grok.Adapter
继承并将接口传递给grok.provides
和{
您需要为您的代码设置更多的上下文。例如,Plone站点充当本地组件注册表。在
最好使用
bin/instance run [scriptname]
命令,它将为您设置数据库连接,并将根对象作为app
传递给脚本。在该脚本中,使用以下样板将脚手架的其余部分安装起来:有了这些,您就可以拥有运行代码所需的一切。别忘了最后打电话给
transaction.commit()
。你的Plone站点可以在局部变量site
中访问。在相关问题 更多 >
编程相关推荐