我使用 Dexterity 制作了一些新的内容类型。我现在希望从 python 脚本创建内容。下面的行一切正常,项目在目标文件夹中生成正确 id 和 日期 .但是如何将文件数据传递给 文件 场,图片 数据到图像字段和 Richt_text 数据到富文本字段?
target.invokeFactory(type_name="content_type_name", id=id, date=date, file=file, image=image, rich_text=rich_text)
我能算出的日期; Dexterity 需要 Python 日期时间格式:
datetime.datetime(2011,1,1)
非常感谢您的帮助——我确信我在这里遗漏了一些非常基本的东西,但还没有找到——可能是因为我找错了地方。
最佳答案
对于文件使用 plone.namedfile.NamedFile 和图像使用 plone.namedfile.NamedImage 和富文本使用 plone.app.textfield.value.RichTextValue
例如
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)
关于content-type - Plone:使用 Dexterity 生成的文件夹式内容类型。如何填充它的文件、图像和富文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6130697/