Python中Plone的条件排序表达式



我正在处理一个文件夹类型内容对象的自定义视图,该对象可拉入多个级别的内容(手册中包含章节,章节中包含文档)。每个自定义内容对象都有各自的数字字段(chapternumber;sectionnumber;docnumber)。我能够在手动级别创建一个视图,以拉入所有内容并显示各自的内容对象编号。

我希望能够排序我的内容对象(按顺序)chapternumber;如果没有,则按sectionnumber;如果没有,则按docnumber;如果不是,那么通过sortable_title。下面是我使用的仅按章节编号排序的TAL语句(下面的代码片段用于按章节编号排序内容,但不显示没有章节编号的内容-因此我想按多个条件排序的原因):

<tal:foldercontents define="
        custom_sort python:{'sort_on': 'chapternumber', 'sort_order': 'ascending'};
        contentFilter contentFilter|request/contentFilter|custom_sort;
        ...

我的自定义视图基于文件夹标准视图模板中的代码:Products.CMFPlone-4.3.2/Products/CMFPlone/skins/plone_content/folder_listing.pt

<tal:foldercontents define="
        contentFilter contentFilter|request/contentFilter|nothing;
        contentFilter python:contentFilter and dict(contentFilter) or {};
        limit_display limit_display|request/limit_display|nothing;
        limit_display python:limit_display and int(limit_display) or None;
        more_url more_url|request/more_url|string:folder_contents;
        is_a_topic python:context.portal_type=='Topic';
        folderContents folderContents|nothing; folderContents python:folderContents or is_a_topic and context.queryCatalog(batch=True, **contentFilter) or context.getFolderContents(contentFilter, batch=True, b_size=limit_display or 9999);
        site_properties context/portal_properties/site_properties;
        use_view_action site_properties/typesUseViewActionInListings|python:();
        Batch python:modules['Products.CMFPlone'].Batch;
        b_start python:request.get('b_start', 0);
        batch python:isinstance(folderContents, Batch) and folderContents or Batch(folderContents, limit_display or 9999, int(b_start), orphan=1);
        isAnon context/@@plone_portal_state/anonymous;
        normalizeString nocall: context/plone_utils/normalizeString;
        toLocalizedTime nocall: context/@@plone/toLocalizedTime;
        show_about python:not isAnon or site_properties.allowAnonymousViewAbout;
        navigation_root_url context/@@plone_portal_state/navigation_root_url;
        pas_member context/@@pas_member;
        plone_view context/@@plone;">
<tal:listing condition="batch">
...

首先,是否可以对自定义视图模板的多个条件进行排序?如果是,我该如何实现它?如果没有,有没有办法实现我想要做的事情?

您需要升级(pin)您的产品。ZCatalog版本到3.0+。从3.0alpha开始添加了多重排序。

这是你可以从CHANGES:

增加了对具有任意数量排序索引和不同sort_order值的sort_on查询的支持。例如:{"foo":"一","sort_on":("foo"、"酒吧")}{"foo":"一","sort_on":"foo"、"酒吧","sort_order":("、"反向")}{"foo":"一","sort_on":("foo"、"酒吧","巴兹")}

最新更新