如何在读取Zope对象数据库的python脚本中为ATFolder对象提供IOrdering适配器?

时间:2014-03-27 21:04:41

标签: position plone adapter

我试图像这样查询portal_catalog:

plone = app['MY-PLONE-SITE-ROOT']

setHooks()
setSite(plone)

gsm = getGlobalSiteManager()

gsm.registerAdapter(ATFolder, (IOrderableFolder,), IOrdering, '')

results = portal_catalog(path={"query":"/MY-PLONE-SITE-ROOT"}, sort_on="getObjPositionInParent")

for brain in results:
    #do something with the folder tree structure
    print brain.getObject().getId()

如果我省略了全局站点管理器和registerAdapter行,那么对“getObjPositionInParent”进行排序会引发ComponentLookupError:

raise ComponentLookupError(object, interface, name)
zope.component.interfaces.ComponentLookupError: (<ATFolder at /MY-PLONE-SITE>, <InterfaceClass plone.folder.interfaces.IOrdering>, u'')

当我在那里尝试注册适配器时,我得到:

TypeError: ('Could not adapt', <Products.ATContentTypes.content.folder.ATFolder object at 0x47d7930>, <InterfaceClass Products.Archetypes.interfaces.schema.ISchema>)

我真的不明白。我应该如何正确地为我的脚本注册适配器?这是从filestorage文件读取ZODB的脚本,因此ZCML不是一个选项。

感谢您提前了解。

0 个答案:

没有答案