content-type - Plone:使用 Dexterity 生成的文件夹式内容类型。如何填充它的文件、图像和富文本字段?

标签 content-type plone variable-assignment dexterity

我使用 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/

相关文章:

css - 为 css 设置内容类型客户端

php - 使用 contentType : 'application/json' not working 的 Ajax 调用

sharepoint - 如何在 Sharepoint 中为内容类型的列设置默认值

python - 如何限制在构造函数之外设置属性?

php - 关于PHP中的内存和变量分配

javascript - 具有解构的对象属性分配?

php - 如何在 PHP 中使用 file_get_contents 获取图像的 MIME 类型

javascript - 如何在开发者 Facebook 中配置设置?

plone - 如何让 instance-Z2.log 注册实际的用户名?

plone - 在仅灵巧的环境中是否仍然需要 aq_inner(和 friend )?