2014/06/06

Title Customization Based On URLs

Plone 網站的 <title /> 內容值,預設是由 Content Title 和 Site Title 合併而成,所以瀏覽首頁時,會看到類似「首頁 -- 我的網站」字樣。我想要把結果改成「我的網站」,方法不止一種,最簡單的方法如下:

到 ZMI portal_view_customization 找到 plone.htmlhead.title,它負責 <title /> 的顯示工作。

定義 is_home 變數,判斷網頁位置是否在首頁。

<tal:block define="state context/@@plone_context_state;
 is_home python:state.is_portal_root() and state.is_default_page()">
<title tal:condition="python: not is_home" tal:content="structure view/site_title">Site Title</title>
<title tal:condition="python: is_home" tal:content="string:我的網站">Site Title</title>
</tal:block>

以上方法只需要編輯 template 內容,不必修改檔案系統裡的 view 程式碼。

2014/06/05

Front Page Editing Made Easy

首頁給人的第一印象,很重要,對 Web Master 而言,他們還在意能否輕易地編輯首頁內容。

長久以來,Plone 有很多模組都想處理這個問題,但改善有限,直到 collective.cover 模組問世,才讓人眼睛一亮。有圖有真相? 先看影片介紹,還有這個範例網站 http://www.vtv.gob.ve/

在實作上,它利用 Cover Content Type 來儲存 Layout 資訊,你可以選用預設 Layout,或是透過 Layout tab 自訂細節。每個小格子被稱為 Tile,它可以再被指派 Carousel、Collection、Embed、RichText 等不同功能。

2014/05/27

plone.i18n Configuration

Plone 多國語文支援,相當成熟,想要讓網站支援中英文訊息介面,下列是基本的設定技巧:

在 ZMI 的 portal_languages 先勾選 Allow combined language codes like de_DE or en_UK. 並儲存,再從 Allowd Languages 欄位設定要支援的語系值,例如同時要支援「中文」和「英文」,可以先點選 Chinese (Taiwan) (zh-tw) 項目,再按住 Ctrl 鍵,點選 English (en) 並儲存,再從 Default Language 欄位選擇預設語系,例如 Chinese (Taiwan) 就行。

Negotiation Scheme 欄位,通常只需要勾選 Use cookie for manual override. 就行。

預設顯示的訊息文字是「繁體中文(臺灣)」,如果想要修改,可以到 plone.i18n/locales/languages.py 檔案,找到下列的設定內容:

u'zh-tw' : {u'name' : 'Chinese (Taiwan)',
 u'native' : '繁體中文(臺灣)',
 u'flag' : u'/++resource++country-flags/tw.gif'},

2014/05/25

Support Our Computer Teachers

"What will happen if users can program their own computer?" This is the question asked in Computer Programming for Everybody (CP4E). Recent developments in computer and communication hardware have given many people access to powerful computers, in the form of desktops, laptops, and mobile devices. It is time to give these users more control over their computers through education and supporting software. If users have a general understanding of computers at the level of software design and implementation, this will cause a massive surge in productivity and creativity, with a far-ranging impact that can barely be anticipated or imagined.

Why Learning CS?

Computer science is a foundational field for every 21st century career or field of study. Learning the basics of computer science prepares students for a world that is increasingly dominated by technology. Research shows that students who study computer science also perform better at math. Besides, computer science is where the jobs are.

Why Python?

A key goal for Education is to guide the learners to solve problems and discover solutions. This principal also applies to computer education (CS classes). Every programming language can be used to teach logical thinking. Why and how can Python stand out in such a language war?

Consider this analogy: When running an international conference, a shared language is required. What should it be and how should it be selected? To efficiently communicate in one language, the ideal choice is one with the lowest learning curve and translation cost. Just as how English has become an international language, I believe Python will become the dominant language in the programming world.

No, Python should not be the only language to learn. For a CS professional, it's common to learn various languages, including C and Java. However, Python is still one of the best languages for beginners and those whose limited resources only provide access to one language.

Give Teachers A Community

Ok, I want to learn Python, how can I find teachers or trainers? There are more and more online Python courses, just to name some, including Codecademy, Coursera, Udacity and LearnStreet. However, there are few, if any, teachers in schools providing courses based on Python. Besides, CS teachers are usually all alone.

Luckily, a global push for more computer science in classrooms is starting to bear fruit. In response to Jessica McKellar's call to action, "Do One Thing Before the next year's PyCon", a group of Taiwan folks run a meetup to support CS teachers, after the PyCon APAC 2014 Education Panel and BoF.

Education is a tree shaking another tree, another cloud to promote a cloud, a soul awakening another soul. -- Karl Theodor Jaspers

Note: thanks to Ken Hu's help on editing this snippet.

2014/04/28

The Next Generation of Programmers

People try to put us d-down (Talkin' 'bout my generation)
Just because we g-g-get around (Talkin' 'bout my generation)
Things they do look awful c-c-cold (Talkin' 'bout my generation)
Yeah, I hope I die before I get old (Talkin' 'bout my generation)

This is my generation
This is my generation, baby

 -- "My Generation", The Who

In a PyCon US 2014 keynote, Jessica McKellar outlined the programming-education problem that exists in US high schools, including lack of teaching and gender imbalance (the 'leaky pipeline' of women in science). She went on highlighting some steps the community could take to help fix it, from policy, student engagement, supporting teachers, and curriculum development. LWN.net provides a good summary on that speech.

"In fact, computer science is the most gender-skewed class."

Jessica is also our PyCon APAC 2014 keynote speaker and education panelist. I believe these programming-education topics will inspire us on how the next generation education looks like.

"If one teacher (Jill Pala) can make that big of a difference, what can a 200,000-member community do?"

So, what will you do in the coming year to help the next generation of Python programmers?

2014/03/27

Plone Theme Barceloneta

隨著 Diazo 和 Mockup 成為 Plone 5 的預設架構,佈景主題也將進入新時代,由 plonetheme.barceloneta 取代 plonetheme.sunburst 成為預設的佈景主題模組。

它的安裝相依需求是 plone.app.theming 模組,這在 setup.py 和 profiles/default/metadata.xml 有載明,在 configure.zcml 則看得到下列三個模組會被載入:

<include package="plone.app.theming" />
<include package="plone.app.widgets" />
<include package="mockup" zcml:condition="installed mockup" />

Diazo 已經存在不少範例,累積一些實戰經驗,但是 Mockup 還處於初步階段,公開的文件還不多。值得注意的是 plone.app.widgets 開始成為表單欄位的輸入介面。

使用 @@manage-viewlets 會看到混亂的畫面,或許還要再修整。

它的 CSS 檔案在 static/barceloneta.min.css,想要修改它,看起來要遵循特定步驟,但還不清楚該怎樣做。

TinyMCE Toolbar Missing

Plone 表單的 RichText 欄位,預設使用 TinyMCE 編輯器,在正體中文環境下,如果遇到 Toolbar 無法顯示的問題,可以執行下列確認動作。

首先要確認 Products.TinyMCE 的版本,這問題在 1.3.5 版本 (2013-08-14 release) 之後有處理掉,而 Plone 4.3.2 預設搭配 Products.TinyMCE 1.3.5,理論上會解決這問題。

因為 Plone 4.3.2 只有 Linux 和 Mac OS X 的安裝檔,Windows 使用者要是下載 Plone 4.3.1 安裝檔,就會遇到這問題。

除了在 Linux 安裝新版 Plone 之外,如果想要手動修訂這問題,可以找到 eggs/Products.TinyMCE-x.y.z-py2.7.egg/Products/TinyMCE/utility.py 檔案,自行加上需要的修訂內容

         AVAILABLE_LANGUAGES = set(
         'sq ar hy az eu be bn nb bs br bg ca ch zh hr cs da dv nl en et fi fr gl '
         'ka de el gu he hi hu is id ia it ja ko lv lt lb mk ms ml mn se no nn fa '
-        'pl pt ps ro ru sc sr ii si sk sl es sv ta tt te th tr tw uk ur cy vi zu'.split())
+        'pl pt ps ro ru sc sr ii si sk sl es sv ta tt te th tr zh-cn zh-tw uk ur cy vi zu'.split())

         if 'LANGUAGE' in context.REQUEST:
-            results['language'] = context.REQUEST.LANGUAGE[:2]
-            if results['language'] not in AVAILABLE_LANGUAGES:
+            if context.REQUEST.LANGUAGE in AVAILABLE_LANGUAGES:
+                results['language'] = context.REQUEST.LANGUAGE
+            elif context.REQUEST.LANGUAGE[:2] in AVAILABLE_LANGUAGES:
+                results['language'] = context.REQUEST.LANGUAGE[:2]
+            else:
                 results['language'] = "en"
         else:
             results['language'] = "en"

如果還是不行,可以用 Google Chrome Browser 的 Inspector 檢查 JavaScript 的狀況,這些資訊通常可當作下一步追蹤的線索。