怎样用程序创建复杂的基于dexterity的内容对象?
这里假定有一个复杂的dexterity内容类型:content_type_name,包括一个file字段,一个image 字段,一个富文本字段,下面的代码演示通过程序来创建这么一个内容对象,并对相应字段赋值:
from plone.namedfile import NamedFile
from plone.namedfile import NamedImage
from plone.app.textfield.value import RichTextValue
file = NamedFile("<html></html>", "text/html", u"text.html")
logo = ... some binary data in a byte string ...
image = NamedImage(logo, filename="logo.gif")
rich_text = RichTextValue(u"<p>A paragraph</p>", 'text/html',
'text/x-html-safe', 'utf-8')
target.invokeFactory(type_name="content_type_name", id=id, date=date, file=file,
image=image, rich_text=rich_text)