I want to have catalog result displayed using the following codes from my Archetypes package. The issue is the displayed listing not according to the positional order in Contents tab. What am I missing?
class BookView(BrowserView):
implements(IBookView)
def get_chapters(self):
context = aq_inner(self.context)
catalog = getToolByName(context, 'portal_catalog')
folder_path = '/'.join(context.getPhysicalPath())
results = catalog(
path={'query': folder_path, 'depth': 1},
portal_type=('File', 'Chapter')
)
return results
<div class="books-pdf"
tal:define="chapters view/get_chapters"
tal:condition="chapters">
<span class="listname"
i18n:translate="">Chapter Name</span>
<span class="iconname"
i18n:translate="">File Type</span>
<span class="sizename"
i18n:translate="">File Size</span>
<tal:chapters repeat="chapter chapters">
...
The catalog returns items in internal order unless you explicitly request an order. You can do so with the
sort_onparameter, which should be the name of an index to use for the sorting.Most indexes can be used for sorting, with the notable exception being full text indexes (which is why there is a
sortable_titleindex in the Plone catalog).You probably want to sort on the
getObjPositionInParentindex, which holds the index of each object in it’s container: