dexterity表單設計(使用Schema-driven types)
plone在dexterity的表單設計上,由淺至深共提供了三個方法
- TTW,透過web介面設計表單,適合網站管理員使用,優點是簡單,但缺點是模組如果停用再啟用,則原來content type的設定都會被覆蓋掉
- Model-driven types,配合TTW使用不失為一個簡單又好用的方法,適合初入門的開發者使用,好處是可以先採TTW設計好表單,透過匯出xml的方式,將表單的xml model直接貼到到模組裏,如此可以不寫程式直接將表單寫到模組裏,增加可重用性,缺點無法進行細部調整。
- Schema-driven types,直接將表單以python程式碼寫到模組程式中,不但可重用性完整,而且可以進行細部調整,適合有經驗的開發者使用。
本文將以Schema-driven types為範例說明,
在表單中,大部份基本的表單型式,幾乎都被定義在以下幾個模組中了
from zope import schema
from plone.app.textfield import RichText
from plone.namedfile.field import NamedBlobImage, NamedBlobFile
schema: 基本欄位,包括 textline, text, bool...., 型式如下
firstName = schema.TextLine(
title=_(u"First name"),
description=_(u"please fill in this field."),
required=True,
)
RichText: rich text欄位,一般會搭配wysiwyg編輯器使用, 型式如下
detail = RichText(
title=_(u"Detail"),
description=_(u"Deatil description."),
required=False,
)
NamedBlobImage, NamedBlobFile: 以blob方式儲存的image,及file欄位
image = NamedBlobImage(
title=_(u"image"),
description=_(u"please upload your image."),
required=False,
)
相關官網文件:
http://docs.plone.org/external/plone.app.dexterity/docs/schema-driven-types.html
http://docs.plone.org/external/plone.app.dexterity/docs/reference/fields.html