按内容中位置顺序排列的目录结果
我想使用我的 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">
...
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">
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您明确请求订单,否则目录会按内部订单返回项目。您可以使用
sort_on
参数来执行此操作,该参数应该是用于排序的索引的名称。大多数索引都可用于排序,但值得注意的例外是全文索引(这就是 Plone 目录中存在
sortable_title
索引的原因)。您可能想要对 getObjPositionInParent 索引进行排序,该索引保存容器中每个对象的索引:
The catalog returns items in internal order unless you explicitly request an order. You can do so with the
sort_on
parameter, 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_title
index in the Plone catalog).You probably want to sort on the
getObjPositionInParent
index, which holds the index of each object in it's container:您需要按此索引对结果进行排序:
You need to sort results by this index: