2009/11/07

TypeError: iteration over non-sequence

這是將 Data.fs 昇級至 Plone 3.3.1 後,同時使用 Plone 2.x 舊式模組時,遇到的問題,症狀是無法將目錄更名,而這個目錄內含 custom content type 的資料。

第一個線索來自 Plone Error Reference 的說明,表示要留意 log 裡 "Could not import class" 的訊息。不過,我沒在 log 裡看到這類的訊息。

第二個線索來自 Archetype Fields Supporting Multiple Selection 的範例,表示要留意 custom content type 裡的欄位屬性,使用 multiValued = 1 時,要配合 LinesField 的欄位。檢查後,看來也都正常。

第三個線索是 ZMI 裡 custom content type 的 Size 欄位空白,而且 log 裡有下列的訊息:
  Module Products.CMFPlone.CatalogTool, line 272, in getObjSize
Module Products.Archetypes.BaseObject, line 590, in get_size
Module Products.Archetypes.Field, line 1501, in get_size
Module Products.Archetypes.Field, line 1486, in get

綜合以上的線索,我懷疑是 custom content type 曾經改版,但資料早在改版前已鍵入,造成版本不一致。

之前 custom content type 也發生過 AttributeError: __getitem__ 的錯誤,此刻的結論,就是再仔細檢查 custom content type 的內容,而且優先清查 LinesField 欄位。

2009/11/05

Custom Plone Home Page

記錄幾個客製 Plone 首頁畫面的技巧。

以 blog style 的首頁為例,新增一個 collection 把 blog 搜尋出來,再於首頁指定顯示這個 collection 即可。想要同時顯示多個 collection 的話,方法之一是尋求擴充模組的支援,像 ContentWellPortlets 就是一個例子。試用 PortletPage 後,覺得是較合用的選項,它可以把 portlet 新增在上下左右共四個區位。

如果想要修改首頁的顯示方式,可以參考 Create a different look and feel for different sections of your web site 這篇文件,利用 sectional CSS 方式來完成。下面的例子,就是把首頁的 heading 和 byline 都取消顯示。

在 portal_skins/custom 裡新增一個 DTML Method 將 Id 設為 sections.css 後,使用下列範例程式碼:

/* <dtml-with base_properties> (do not remove this :) */
/* <dtml-call "REQUEST.set('portal_url', portal_url())"> (not this either :) */

.section-front-page
.documentFirstHeading {
display: none;
}
.documentByLine {
display: none;
}

/* </dtml-with> */

到 portal_css 裡新增一個 stylesheet 填寫 ID 為 sections.css 其他都使用預設值。必要的話,可以設定 Plone 在 debug mode 執行,並勾選 portal_css 的 Debug/development mode 讓修改結果馬上生效。

還有許多修改技巧,可以在 Plone 3 Theming 這本書裡看到。

另外,使用 Plone 3.3.1 的朋友,可能會發現 collection 設定 criteria 時的錯誤,請參考 Impossible to add a criteria in a collection in 3.3.1 的修訂方法,先處理掉這個問題。

2009/10/19

Content Type Workflow Configuration



workflow 是一種 state machine,在 Plone 系統的脈絡裡,就是指 content type 生命週期裡的可能狀態。Plone 預設提供完整的 (role-based) workflowcontent rule 功能,是開放源碼 CMS 裡少數具備這項特色的產品,藉由 workflow 和 content rule 的支援,我們可以針對 content type 或目錄各別指定工作流程或自動化程序。


進入 ZMI 的 portal_workflow 可以從 Contents 頁籤查看既有的工作流程項目,除了預設啟用的 simple_publication_workflow 之外,還有 one_state_workflow 和 intranet_workflow 等。


舉例來說,想讓新建的文件馬上對外公開,可採用 one_state_workflow 設定值,因為它只有 public 一種狀態。

在 Workflows 頁籤可看到預設 (Default) 的指定值,和 type 與 workflow 的指定列表。


舉例來說,想要把 News Item 設定成 one_state_workflow 工作流程,就把 (Default) 改為 one_state_workflow 按 Change 鈕,再按 Update security settings 確認更新的動作。

2009/10/14

Embed Gmap HTML Code in Plone

想在 Plone 預設的 kupu editor 裡嵌入 Gmap HTML 內容,先到 Site Setup 裡 HTML Filter 項目。

設定內容的下方 Custom tags 新增 iframe 並儲存。
從 Google Map 找到的地圖,左上方選項 Link 裡的 Paste HTML to embed in website 複製內容,嵌入到自己想要的內容位置。
另外像 flickr, youtube 的內容嵌入原理類似。

2009/10/07

Plone Navigation Tree Tips

Plone 的 portlet 包括 navigation (稱為導覽) 的項目,預設會指示正在閱讀的文件位置,如果想要控制位置顯示的細節,文件 How to hide an item from the navigation tree even it is the current item 介紹 Plone 2.5 環境的技巧,想在 Plone 3.x 環境完成類似的效果,方法很多種,文件 How to really exclude from navigation 裡有介紹範例。

2009/10/03

Plone Developer Manual

之前要讀 Plone 技術文件,會從 Plone Core Developer ReferenceArchetypes Developer 找起,現在多了一篇 Plone Developer Manual。這份新手冊的目標,就是要統整並取代舊有散落各處的文件
目前還是草稿階段,最早是由 Mikko Ohtamaa 帶頭發起,並讓社群協力維護
我最關心 Sessions and cookies 的章節,它應該可以處理 PlonePAS 整合 PHP 應用軟體的議題,而且還得繼續學習 HTTP 資料傳輸的底層原理。

2009/09/24

Changing Tabs in Plone

在 Plone Site 根目錄 (root folder) 所建立的項目,例如 (id = about, title = 認識協會) 目錄,它會自動以 tab 型式出現,就像下圖裡的 1。
讀取各別文章時,會有 You are here: 的提示,如圖裡的 2。左方可以有 navigation portlet 導覽視框,如圖裡的 3。

我們也可以讓新增的項目,不要"自動"出現在 tab 位置,方法是從 Site Setup 點選 Navigation Setting 導覽設定,取消"自動產生"的設定值。


完成上述的設定調整後,除了"首頁"之外,其他 tab 都不會自動出現。

接著,想再把"認識協會"加回 tab 位置,先進入 ZMI 到 portal_actions/portal_tabs 畫面,從右上方選 CMF Action 來新增。



ID 欄位填 about。



再點選 about 進去填其他詳細資料,注意到 Permissions 欄位選擇 View,而且 Visual? 要勾選生效。



至此,我們在 portal_tabs 裡有兩個 CMF Action,分別是 index_html 和 about,還可以用 Up / Down 或 Top / Bottom 來控制順序。



想要讓某個 tab 未登入前看不見,登入後才看得到,要在 Condition 欄位裡填 python: member,想要讓某個 tab 只有管理員才看得到,要在 Condition 欄位裡填 python:portal.portal_membership.getAuthenticatedMember().has_role('Manager')


以上說明參考自 http://plone.org/documentation/how-to/changing-tabs