2012-01-11 77 views
0

我想使用以下代码从我的Archetypes包中显示目录结果。问题是显示的列表不符合内容选项卡中的位置顺序。我错过了什么?目录结果按位置顺序排列内容

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"> 
    ... 

回答

8

目录返回内部订单项目。您可以使用sort_on参数来完成此操作,该参数应该是用于排序的索引的名称。

大多数索引可以用于排序,显着的例外是全文索引(这就是为什么在Plone目录中有sortable_title索引)。

你可能想排序的getObjPositionInParent指数,后者持有它的每个对象的索引的容器:

results = catalog(
     path=dict(query=folder_path, depth=1), 
     portal_type=('File', 'Chapter'), 
     sort_on='getObjPositionInParent', 
    ) 
1

您需要通过这个指标来对结果进行排序:除非您明确请求判令

getObjPositionInParent