indexing - What is the best way to get a content object's position in the parent? Plone 4 -


i traversing folders content items within them. use portal_catalog brains searched on paths. brains have access metadata, , brain.getobject() return actual object. have gotten parent object brain.getobject().aq_parent. want object's position in parent. @ first tried brain.getobject().getobjpositioninparent(), , afterwards, realized getobjpositioninparent() attribute accessible index data.

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} 

when printed out screen, see of items within dict returned catalog.getindexdataforrid call. problem of objects, getobjpositioninparent() empty array ([]). on page http://developer.plone.org/searching_and_indexing/query.html, appears value should integer. made me wonder if have go create index data, and, if so, might reaching far outward object data must there (since folders know position put each child in). best way content object's position in parent? in advance information?

more:

i unsure why adapter cannot found, may have lack of registering it. script build zope environment read zodb directly file opposed on top of running zope instance. possible have register adapter globalsitemanager?

thank you, mathias. when use sort_on="getobjpositioninparent", following error:

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: (&lt;atfolder @ /sanford guide web edition/amt&gt;, &lt;interfaceclass plone.folder.interfaces.iordering&gt;, u'') 

the best way index itself.

code snipped based on catalogtool (products.cmfplone)

from acquisition import aq_inner acquisition import aq_parent ofs.interfaces import iorderedcontainer  obj = brain.getobject() parent = aq_parent(aq_inner(obj)) ordered = iorderedcontainer(parent, none) if ordered not none:     return ordered.getobjectposition(obj.getid()) return 0 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -