Hor*_*rst 4 content-type plone variable-assignment dexterity
我使用Dexterity制作了一些新的内容类型.我现在希望从python脚本创建内容.一切都与下面的行一致,并在目标文件夹中生成具有正确的id和日期的项目.但是,如何将文件数据传递到文件字段,将图像数据传递到图像字段,将richt_text数据传递给rich_text字段?
target.invokeFactory(type_name="content_type_name", id=id, date=date, file=file, image=image, rich_text=rich_text)
Run Code Online (Sandbox Code Playgroud)
我能搞清楚的日期; Dexterity需要Python日期时间格式:
datetime.datetime(2011,1,1)
Run Code Online (Sandbox Code Playgroud)
非常感谢你的帮助 - 我确信我在这里缺少一些非常基本的东西,但还没有找到它 - 可能是因为我在找错了地方.
对于文件使用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)
Run Code Online (Sandbox Code Playgroud)