开发者

Plone:Folderish content type generated with Dexterity. How do I populate it's file, image and rich text fields?

I have made some new content type using Dexterity. I now wish to create the content from a python script. All is well with the line below, and the item is generated in the target folder with the correct id and date. But how do you pass the file data to a file field, the image data to the image field and the richt_text data to the rich_text field?

target.invokeFactory(type_name="content_type_name", id=id, date=date, file=file, image=image, rich_text=rich_text)

The date I could figure out; Dexterity wants the Python date开发者_运维问答time format:

datetime.datetime(2011,1,1)

Thank you very much for your help - I am sure I am missing something quite elementary here, but haven't found it - probably because I am looking in the wrong place.


For file use plone.namedfile.NamedFile and for image use plone.namedfile.NamedImage and for rich text use plone.app.textfield.value.RichTextValue

e.g.

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜