我希望使用我的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">
...
Run Code Online (Sandbox Code Playgroud)
除非您明确请求订单,否则目录将按内部顺序返回项目.您可以使用sort_on参数执行此操作,该参数应该是用于排序的索引的名称.
大多数索引都可以用于排序,值得注意的例外是全文索引(这就是sortable_titlePlone目录中有索引的原因).
您可能希望对getObjPositionInParent索引进行排序,该索引保存其容器中每个对象的索引:
results = catalog(
path=dict(query=folder_path, depth=1),
portal_type=('File', 'Chapter'),
sort_on='getObjPositionInParent',
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
599 次 |
| 最近记录: |