Listing for Folder and Collection
想要顯示目錄裡的項目,要考量過濾條件,所有具備 IFolderish 介面的物件,會提供 contentItems() 之類的函式。
預設的顯示方式,包括:標準方式 (Standard View) 概要方式 (Summary View) 所有內容 (All Content) 表格方式 (Tabular View) 圖示方式 (Album View),安裝 plone.app.event 的話,還有活動列表 (Event Listing) 方式。
在 plone.app.contenttypes/profiles/default/types/Folder.xml 看得到顯示方式的註冊值:
<property name="view_methods"> <element value="folder_summary_view" /> <element value="folder_full_view" /> <element value="folder_tabular_view" /> <element value="atct_album_view" /> <element value="folder_listing" /> </property>
folder_listing (Standard View) 是預設啟用的顯示方式,它也是各種顯示方式的基礎,其他顯示方式預設會繼承它的變數值:
<property name="default_view">folder_listing</property>
實作的 View 程式碼,被註冊在 plone.app.contenttypes/browser/configure.zcml 裡:
<browser:page name="folder_listing" for="plone.app.contenttypes.interfaces.IFolder" layer="plone.app.contenttypes.interfaces.IPloneAppContenttypesLayer" template="templates/folder_listing.pt" permission="zope2.View" menu="plone_displayviews" title="Standard view" />
Folder Summary View
從 Plone 4 開始,新增 content-core slot 功能。
<a href="#" tal:condition="exists:item_object/@@images/image" tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url)"> <img src="" alt="" tal:replace="structure item_object/@@images/image/mini" /> </a>
HeadLineView Macro 經驗記錄: 想沿用 Summary View Template (listing_summary.pt) 來改,它有繼承 Standard View (listing.pt) 用到 text-field-view macro 自訂 view/text 無法直接只套用 Template,方法一是要註冊沿用 CollectionView,方法二是繼承 CollectionView 來修改。
All Content 使用 @@full_view templates/full_view.pt 並搭配 @@full_view_item full_view.py templates/full_view_item.pt
plone.app.contentlisting
Plone 4.1 之後的建議方式,在 Template 裡先使用下列程式碼取得目錄裡的項目內容:
context/@@folderListing
這個 @@folderListing 只支援 Folder 但不支援 Collection,這名稱只因向前相容而留下來,建議改用 @@contentlisting 了。
下列是產生列表最簡化的範例:
<ul>
<li tal:repeat="item context/@@contentlisting" tal:content="item/Title" />
</ul>
加上型別參數的範例:
<li tal:repeat="item python:context.restrictedTraverse('@@contentlist')(portal_type='Document')">
查詢現行目錄的檔案列表 plone.app.contentlisting/browser.py
class FolderListing(BrowserView): def __call__(self, batch=False, b_size=20, b_start=0, orphan=0, **kw): query = {} query.update(kw) query['path'] = {'query': '/'.join(self.context.getPhysicalPath()), 'depth': 1} catalog = getToolByName(self.context, 'portal_catalog') results = catalog(query)
Dexterity
The dvpdf-group-view is registered in configure.zcml for Products.CMFCore.interfaces._content.IFolderish. Dexterity containers, and custom folders built from Dexterity containers, do not have this interface. Allowing the view on plone.dexterity.interfaces.IDexterityContainer would enable dvpdf-group-view to be used from Dexterity folders. Possibly, the inclusive interface is OFS.interfaces.IFolder. container interface for collective.documentviewer dvpdf-group-view
排序
最早有提議 View Template 提供排序功能,方法之一,是透過 Products.CMFPlone-4.3.2-py2.7.egg/Products/CMFPlone/skins/plone_scripts/getFolderContents.py getFolderContents 可以調整 folder_listing 的排序。
# Modification to alter sort order contentFilter['sort_on'] = "modified" contentFilter['sort_order'] = "descending"
Changing Plone's folder listing sort order 提供三種方法。
plone.folder 強化排序功能 顯示圖檔縮圖
指定在 Contents 裡的 top 或 bottom 位置
http://mysite/myfolder/folder_position?position=top&id=myitem
利用 getFolderContents Script 調整排序方式
Collection Query
query 欄位的儲存值範例 [{u'i': u'getId', u'o': u'plone.app.querystring.operation.string.is', u'v': u'aggregator'}]
results 方法的結果範例 <plone.batching.batch.BaseBatch object>
顯示數量
Folder 每頁顯示數量的預設值是 100,設定在 plone.app.contenttypes/browser/templates/folder_listing.pt 檔案裡,請參考 folderContents 和 batch 變數。
Collection 提供顯示數量的設定欄位,
plone.batch 支援 Slicing 比分頁數多1的情況會直接顯示在前一頁
顯示文件
collective.documentviewer instead of wc.pageturner
顯示活動
event_listing Graceful date_for_display When No start/end
collective.folderishtraverse: traverse to first item in folder
客製顯示欄位
collective.listingviews tutorial body field
OFS.CopySupport.manage_pasteObjects: archive old content by moving it into another folder