2013/01/27

Newline to BR in Description Field

Usually we want newlines in the description field be interpreted as <br /> for Plone contents. Here is a qucik trick:

Products/CMFPlone/skins/plone_kss/kss_generic_macros.pt
37c37,38
< templateId='kss_generic_macros', macro='description-field-view');"
---
> templateId='kss_generic_macros', macro='description-field-view');
> pps modules/Products.PythonScripts.standard"
41c42
< tal:replace="context/Description">
---
> tal:replace="structure python:pps.newline_to_br(pps.html_quote(context.Description()))">

2013/01/14

Disqus Service Integration

Disqus 是一個留言服務系統,目前全球市佔率在前三名內。在 2012 年之際,版本昇級後稱為 Disqus 2012,介面和 API 有了較大的調整,增加 Community 和 Discovery 的功能。

想在 Plone 裡整合這項服務,最簡單的方式是透過 collective.disqus 模組。安裝後的設定步驟,有下列要點:

先要勾選 Activate Disqus as system coment 來啟用,填寫 API key 資料。

在 Site Setup 的 Discussion 設定項目裡,勾選 Globally enable comments 來啟用留言功能。

再到 Site Setup 的 Type 設定項目,個別依照 Content Type 指定 Allow comments。

有遇到 JavaScript 變數未被嵌入的問題,造成畫面只出現 blog comments powered by Disqus 的字樣,下載 github 上的最新程式碼就解決了。

最後,據說有多國語文的支援了,還沒有空仔細測試這部份。

Update Plone TinyMCE

舊版 TinyMCE 編輯器和 IE 9 有相容問題,至少要昇級到 Products.TinyMCE 1.3 之後的版本,以 Plone 4.2.1 為例,它的 versions.cfg 原本的內容是:

Products.TinyMCE = 1.2.13

可以改成:

Products.TinyMCE = 1.3b4

重跑 buildout 後,額外會安裝的模組包括:

plone.namedfile==1.0.6
plone.rfc822==1.0
zope.app.file==3.6.1

測試上述方式時,對新建的 Plone Site 沒問題,不過,把舊系統昇級的結果,有遇到編輯器顯示不正常的問題,猜想是 GenericSetup profile 沒有完整啟用所造成,沒時間追下去便作罷。

或者,直接改用 Plone 4.3 以上的版本,內建的 TinyMCE 就是 1.3 之後的版本。

2013/01/05

Mapping Contributors

mr.cabot 是個工具軟體,它會讀取 GitHub、gmane、StackOverflow 的資料,試圖把專案貢獻人員的地理位置找出來,最後在地圖上標示。

主要設定檔是 mr.cabot.cfg,輸出格式預設是 Google Static Map,也可以使用 HTML 或 KML。

2012/12/28

Add Author Name to Collection Portlet

By default the Plone collection portlet will display item's title only. We might want add other info for the item listing. Here is an example to add Author Name in plone.portlet.collection/collection.pt:

     itemUrl    python:useView and obj.getURL() + '/view' or obj.getURL();
-    item_icon python:getIcon(obj);"
+    item_icon python:getIcon(obj);
+    itemCreator python:obj.getObject().Creator();
+    author python:context.portal_membership.getMemberInfo(itemCreator);
+    authorName python: author and author['fullname'] or itemCreator"

Note that using Creator() instead of Creator, or you will fail when passing itemCreator to portal_membership.getMemberInfo(). This is adapted from codes in plone.app.layout/viewlets/content.py

Prof. Chen Interview by PanSci

Quotes from the interview by PanSci

如果學術界不被論文發表綁架,培養出的優秀學生可以在社會各角落,像是檢驗公司,成為專業又公正的檢驗員,未必要留在學校作學術研究;只要不背離知識的核心價值,就能成為校正社會的力量。

就像我年輕的時候讀過的《天地一沙鷗》,族群裡總有幾隻個體認為自己的翅膀是為了某些更偉大的事而存在的,不該留自己在地上;人類社會也是如此,我認為大學裡頭這樣的個體應該比例上要多一點。

如果全台灣的大學-包括台大的研究背後真正的目的都是為了教學,而不是學術發表,那我們的視野會變得很不一樣。

2012/12/18

Plone Template Global Variables

It is a common task to get information about the state of your site and other global variables. For Plone 4+, the recommended approach is to use one of the following browser views:

  • @@plone_portal_state
  • @@plone_context_state
  • @@plone_tools

You can find how they are defined in plone.app.layout/globals/configure.zcml:

<browser:page
   name="plone_tools"
   for="*"
   permission="zope.Public"
   class=".tools.Tools"
   allowed_interface=".interfaces.ITools"
   />

<browser:page
   name="plone_context_state"
   for="*"
   permission="zope.Public"
   class=".context.ContextState"
   allowed_interface=".interfaces.IContextState"
   />

<browser:page
   name="plone_portal_state"
   for="*"
   permission="zope.Public"
   class=".portal.PortalState"
   allowed_interface=".interfaces.IPortalState"
   />

For example, a straight way to add the homepage link:

<a href="http://www.yoursite.com/">home</a>

This works only for the site running on the specific domain name. When testing, you are likely to run on localhost or IP address, that the homepage URL needs updated accordingly. The recommended style looks like this:

<a href="#"
   tal:define="home_url context/@@plone_portal_state/portal_url"
   tal:attributes="href home_url">home</a>