Created
March 7, 2009 04:08
-
-
Save btbytes/75218 to your computer and use it in GitHub Desktop.
Create Plone Documents programatically from the shell/script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
create_plone_doc.py | |
Create Plone Document from debug shell. | |
Useful for creating content automatically in Plone. Think data import from other CMSes. etc. | |
''' | |
from wrap import wrap #see http://gist.github.com/75207 | |
from Products.CMFCore.utils import getToolByName | |
import transaction | |
app = wrap(app, 'admin', 'passwd') | |
# `test` is the plone site | |
urltool = getToolByName(app.test, 'portal_url') | |
portal = urltool.getPortalObject() | |
#place you want to create the content, here its the root of the site | |
container = portal | |
#create a transaction | |
t = transaction.get() | |
#create an object | |
id = 'helloworld' | |
container.invokeFactory(type_name="Document", id=id) | |
doc = container[id] | |
doc.setTitle("Hello world") | |
doc.setText("<h3>Section 1</h3> <p>Introduction</p>") | |
#is the doc published? No. | |
container.portal_workflow.getInfoFor(doc, 'review_state', '') | |
wftool = container.portal_workflow | |
wftool.doActionFor(doc, 'publish', comment='publishing programmatically') | |
# set Tags | |
doc.setSubject(('foo', 'bar')) | |
# allow comments | |
doc.allowDiscussion(True) | |
#exclude from navigation as this is in top level | |
#and default behaviour is to create a nav tab for children at root | |
doc.setExcludeFromNav(True) | |
#Create a folder | |
id = 'programming' | |
container.invokeFactory(type_name="Folder", id=id) | |
fol = container['programming'] | |
wftool.doActionFor(fol, 'publish', comment='publishing folder') | |
# commit changes | |
t.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment