add contents and publish in plone using python script

add a external method
in the method’s python file

Newfolder = context.invokeFactory(“Folder”, id=”NEWFOLDERINPLONE”, title=”NEWFOLDERINPLONE”,path=’/’.join(context.getPhysicalPath()))
this will add a new folder in the contexts directory
To publish this folder automatically by code try this magic

Newfolderobj = getattr(context, Newfolder, None)
review_state = Newfolderobj.portal_workflow.getInfoFor(Newfolderobj, ‘review_state’, ”)
if not review_state == ‘published’:
Newfolderobj.portal_workflow.doActionFor(Newfolderobj,”publish”,comment=”publised programmatically”)

it will be published in site on the fly…

to add page template

idict = { ‘id’ : ‘step1Page’
, ‘type’: ‘page template’
, ‘body’: page_template_body # variable can be a content of a pt file
, ‘workflow_action’: ‘publish’
, ‘workflow_comment’: ‘This item published programmatically’

}

Newfolderobj.manage_addProduct[‘PageTemplates’].manage_addPageTemplate(id=idict[‘id’])
oi = getattr(Newfolderobj,idict[‘id’])
oi.pt_edit(idict[‘body’],’text/html’)

this will add a page template in new folder
together


def main(self):

# Example code:

# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
context = self
try:
Newfolder = context.invokeFactory("Folder", id="NewFolderUnusedId", title="NewFolderUnusedId",path='/'.join(context.getPhysicalPath()))
except:
Newfolder = 'NewFolderUnusedId'

Newfolderobj = getattr(context, Newfolder, None)

review_state = Newfolderobj.portal_workflow.getInfoFor(Newfolderobj, 'review_state', '')
if not review_state == 'published':
Newfolderobj.portal_workflow.doActionFor(Newfolderobj,"publish",comment="publised programmatically")
f=open("somefile.pt","r")
page_template_body = f.read()
f.close()
idict = { 'id' : 'step1Page'
, 'type': 'page template'
, 'body': page_template_body
, 'workflow_action': 'publish'
, 'workflow_comment': 'This item published programmatically'

}

Newfolderobj.manage_addProduct['PageTemplates'].manage_addPageTemplate(id=idict['id'])
oi = getattr(Newfolderobj,idict['id'])
oi.pt_edit(idict['body'],'text/html')
return true

Advertisements
About

Work is fun!

Tagged with: , , , , , ,
Posted in Uncategorized
One comment on “add contents and publish in plone using python script
  1. Jason Hammons says:

    Thank you for the reference. I found this useful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Disclaimer
All content provided on this "tareqalam.com" blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner of [tareqalam.wordpress.com] will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
March 2009
M T W T F S S
« Dec   Apr »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 23 other followers

%d bloggers like this: