使用 paster 新增content type

使用zopeskel開啟新專案後,目前仍是一個空的專案,裏面所有內容都是環境設定相關

因此,我們要開始依需求來開發專案了

在plone,並沒有sql這種關聯式資料庫的概念,取而代之的是程式開發中類別(class)的概念

因此,我們將不同的性質的頁面需求,視為各種不同的 "content type".各種content type的實例化(Instance),則稱為content .

例如,普通頁面是一種content type,新聞是一種content type,事件也是一種content type...

plone預設,已經有的content type有以下幾種

  • Event
  • Image
  • News Item
  • File
  • Folder
  • Link
  • Page

如果需求超過以上所涵蓋的範圍,則必需客製化content type,

「paster」就提供了這種的功能

在專案的根目錄下,執行

../../bin/paster addcontent dexterity_content

Enter contenttype_name (Content type name ) ['Example Type']: (輸入content type名稱,這裏以 namecard 為例)

Enter contenttype_description (Content type description ) ['Description of the Example Type']: (content type 文字說明)

Enter folderish (True/False: Content type should act as a container ) [False]: (是否要成為目錄,預設False,若輸入True,則這個content type會成為目錄型態,也就是在底下還可以再新增content)

Enter global_allow (True/False: Globally addable ) [True]: (是否可以新增content,預設True,所以可以在plone站點新增content,若選False,則之後無法在網站新增content, 什麼情況下會新增一個content type,但卻不給新增content?這種情況我們會在以後的文章舉例說明)

Enter allow_discussion (True/False: Allow discussion ) [False]: (是否允許討論,預設False,若選True, 則在新增的content底下,會有網友留言的功能)

回答完以上問題,paster會自動產生相對應的py檔(以本例,會產生出namecard.py),

相關的環境設定值也會自動插入到configure.zcml及*.xml,可以說是相當方便