I've been using this recipe for quite a while now, and as a result
have extended it to include editing of metadata, attributes, and
properties where they apply. I've also included the routines for
adding page templates.
Typically I'm programmatically adding content from files in the file
system so I'll use a dictionary to control the item attributes...
o = context or folder object where content being added
oi = item
Page Templates
idict = { 'id' : 'documentId'
, 'type': 'page template'
, 'body': *ZPT template here*
}
o.manage_addProduct['PageTemplates'].manage_addPageTemplate(id=idict['id'])
oi = getattr(o,idict['id'])
oi.pt_edit(idict['body'],content_type)
CMF Type
idict = { 'id' : 'documentId'
, 'type': 'Document'
, 'title': 'This is a Document'
, 'description': 'This is the document description'
, 'subject': 'document, automated'
, 'body': 'This is the body of the document which will be added'
, 'workflow_action': 'publish'
, 'workflow_comment': 'This item published programmatically'
}
o.manage_addProduct['CMFDefault'].manage_addContent(type=idict['type'],id=idict['id'])
oi = getattr(o,idict['id'])
oi.editMetadata( title=idict['title']
, description=idict['description']
, subject=idict['subject']
)
oi.edit(text_format='', file='', text=idict['body'])
review_state = oi.portal_workflow.getInfoFor(oi, 'review_state', '')
# validate review state, and set to published if has not been set to
# published previously
#
if not review_state == 'published':
oi.portal_workflow.doActionFor(oi,idict['workflow_action'],
comment=idict['workflow_comment'])
Portal Folder
idict = { 'id' : 'FolderId'
, 'type': 'Folder'
, 'title': 'This is a Folder'
, 'description': 'This is the folder description'
}
o.invokeFactory(type_name=idict['type'], id=idict['id'])
oi = getattr(o,idict['id'])
oi.edit(title=idict['title'],description=idict['description']) |