Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Listing for Folder and Collection

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

Archetypes NewsItem Image

顯示 SubFolder 內容

從 Plone 4 開始,新增 content-core slot 功能。

plone.app.imaging 範例

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

plone.app.contentlisting

Plone 4.1 之後的建議方式,在 Template 裡先使用下列程式碼取得目錄裡的項目內容:

context/@@folderListing

下列是產生列表的範例:

<ul>
<li tal:repeat="item context/@@folderListing" tal:content="item/Title" />
</ul>

查詢現行目錄的檔案列表 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 調整排序方式

取得 position 設定值

指定在 Navigation Portlet 的位置

顯示數量

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

collective.formcriteria

OFS.CopySupport.manage_pasteObjects: archive old content by moving it into another folder