我正在遍歷其中包含內容項的文件夾。我使用portal_catalog在特定路徑上搜索大腦。大腦可以訪問元數據,brain.getObject()將返回實際的對象。我已經通過brain.getObject()。aq_parent獲得了父對象。現在我想要獲取父對象的位置。起初,我嘗試了brain.getObject()。getObjPositionInParent(),之後,我意識到getObjPositionInParent()是一個可以從索引數據訪問的屬性。什麼是最好的方式來獲取父對象的內容對象的位置? Plone 4
idxData = catalog.getIndexDataForRID(brain.getRID())
sJson = json.dumps(idxData)
l = brain.getObject()
lUpdate = {'path': '/'.join(l.getPhysicalPath()), 'meta_type': l.meta_type, 'title':l.getRawTitle(), 'remoteUrl': l.getRemoteUrl(), 'json':sJson}
當我將其打印到屏幕上時,我看到從catalog.getIndexDataForRID調用返回的字典中的所有項目。問題是,對於所有的對象,getObjPositionInParent()是一個空數組([])。在此頁面http://developer.plone.org/searching_and_indexing/query.html上,它顯示的值應該是一個整數。這讓我想知道是否必須創建索引數據,如果是這樣,那麼我可能會遠離對象以獲取必須已經存在的數據(因爲文件夾顯然知道每個孩子的位置)在)。獲取內容對象在父級中的位置的最佳方式是什麼?提前感謝任何信息?
更多:
我不確定爲什麼適配器無法找到,但它可能與缺乏註冊它做。這是一個腳本,我構建Zope環境以直接從文件中讀取ZODB,而不是在運行的Zope實例之上。是否有可能需要使用GlobalSiteManager註冊適配器?
謝謝Mathias。當我使用的sort_on =「getObjPositionInParent」,我得到以下錯誤:
Traceback (most recent call last):
File "extractMenuStructure.py", line 459, in <module>
res = processFolder(home['childItems'], '/Sanford Guide Web Edition/' + appFolderNm + '', config['screens'])
File "extractMenuStructure.py", line 390, in processFolder
results = portal_catalog(path={"query":currentPath, "depth":d},sort_on="getObjPositionInParent")
File "/Applications/Plone/buildout-cache/eggs/Products.CMFPlone-4.1.2-py2.6.egg/Products/CMFPlone/CatalogTool.py", line 427, in searchResults
return ZCatalog.searchResults(self, REQUEST, **kw)
File "/Applications/Plone/buildout-cache/eggs/Products.ZCatalog-2.13.20-py2.6.egg/Products/ZCatalog/ZCatalog.py", line 604, in searchResults
return self._catalog.searchResults(REQUEST, used, **kw)
File "/Applications/Plone/buildout-cache/eggs/Products.ZCatalog-2.13.20-py2.6.egg/Products/ZCatalog/Catalog.py", line 909, in searchResults
return self.search(args, sort_index, reverse, sort_limit, _merge)
File "/Applications/Plone/buildout-cache/eggs/Products.ZCatalog-2.13.20-py2.6.egg/Products/ZCatalog/Catalog.py", line 658, in search
b_size=b_size)
File "/Applications/Plone/buildout-cache/eggs/Products.ZCatalog-2.13.20-py2.6.egg/Products/ZCatalog/Catalog.py", line 678, in sortResults
index_key_map = sort_index.documentToKeyMap()
File "/Applications/Plone/buildout-cache/eggs/plone.app.folder-1.0.4-py2.6.egg/plone/app/folder/nogopip.py", line 91, in documentToKeyMap
ids = folder.getOrdering().idsInOrder()
File "/Applications/Plone/buildout-cache/eggs/plone.folder-1.0.1-py2.6.egg/plone/folder/ordered.py", line 41, in getOrdering
adapter = getAdapter(self, IOrdering)
File "/Applications/Plone/buildout-cache/eggs/zope.component-3.9.5-py2.6.egg/zope/component/_api.py", line 96, in getAdapter
raise ComponentLookupError(object, interface, name)
zope.component.interfaces.ComponentLookupError: (<ATFolder at /Sanford Guide Web Edition/amt>, <InterfaceClass plone.folder.interfaces.IOrdering>, u'')
謝謝,但在嘗試,我得到一個當ordered.getObjectPosition(obj.getId())被稱爲ComponentLookupError。它說實現IOrdering的ATFolder找不到適配器。還有什麼想法? – user1075722
@ user1075722你可以在什麼地方發佈完整的回溯? – Mathias
嗨,@Mathias。我添加了堆棧跟蹤和錯誤輸出。謝謝你的幫助。 – user1075722