Create objects in Plone
by
Wyden Silvan
—
last modified
20.01.2010 10:23
# Find our target folder from the context.
target = context
# We need to engineer a unique ID for the object we're
# going to create. If your form submit contained a field
# that was guaranteed unique, you could use that instead.
from DateTime import DateTime
uid = str(DateTime().millis())
# We use the "invokeFactory" method of the target folder
# to create a content object of type "Document" with our
# unique ID for an id and the form submission's topic
# field for a title.
target.invokeFactory("Document", id=uid, title=form['topic'])
# Find our new object in the target folder
obj = target[uid]
# Set its format, content and description
obj.setFormat('text/plain')
obj.setText(form['comments'])
obj.setDescription(form['replyto'])
# Force it to be reindexed with the new content
obj.reindexObject()
