[CMF-checkins] CVS: CMF/CMFWorkspaces/skins/workspaces - content_add.py:1.1

Shane Hathaway shane@cvs.zope.org
Fri, 12 Jul 2002 11:50:23 -0400


Update of /cvs-repository/CMF/CMFWorkspaces/skins/workspaces
In directory cvs.zope.org:/tmp/cvs-serv27300

Added Files:
	content_add.py 
Log Message:
This is an example factory skin method.


=== Added File CMF/CMFWorkspaces/skins/workspaces/content_add.py ===
##parameters=type, workspace=None
##title=Adds an object to a BTreeFolder, generating the ID
# Example factory skin method that uses IDs generated by a destination
# BTreeFolder.

dest = context.portal_organization.getTypeContainer(type)

prefix = '%s-%s-' % (container.ZopeTime().strftime('%Y%m%d%H%M'),
                    type.replace(' ', ''))

id = dest.generateId(prefix, rand_ceiling=9999)

if not dest.checkIdAvailable(id):
    return dest.error_id_in_use()

RESPONSE = context.REQUEST['RESPONSE']
dest.invokeFactory(type, id, title='', RESPONSE=RESPONSE)

ob = dest[id]
if workspace is not None:
    ws = context.restrictedTraverse(workspace)
    ws.addReference(ob)
context.portal_lock.lock(ob) # Lock it on creation

# Note that invokeFactory() causes a redirection.