[Zope-CMF] Files to Portal Files conversion script
David Chandek-Stark
dc at duke.edu
Wed Oct 22 19:31:52 EDT 2003
Turns out, all I had to do was this:
###
request = container.REQUEST
response = request.RESPONSE
mainfolder = container
temp = 'temp'
mainfolder.manage_addPortalFolder( temp )
tempfolder = getattr( mainfolder, temp )
files = mainfolder.objectValues( 'File' )
for f in files:
tempfolder.invokeFactory( 'File', f.id(), title=f.title,
precondition=f.precondition, content_type=f.content_type, file=f.data )
###
Thanks to Florent Guillaume for an assist.
--David
David Chandek-Stark wrote:
> Looking for comments on this script, which takes all objects in its
> folder (Portal Folder) of type 'File', and create analagous objects in a
> 'temp' subfolder of type 'Portal File'. It appears to work, but the
> manage_upload() call, especially, feels like a hack. P.S. I'm a relative
> Python newbie. Thanks--David.
>
> ###
> request = container.REQUEST
> response = request.RESPONSE
> mainfolder = container
> temp = 'temp'
> mainfolder.manage_addPortalFolder( temp )
> tempfolder = getattr( mainfolder, temp )
> files = mainfolder.objectValues( 'File' )
>
> for f in files:
> p_disp = tempfolder.manage_addProduct[ 'CMFDefault' ]
> p_disp.manage_addContent( f.id(), 'Portal File' )
> newfile = getattr( tempfolder, f.id() )
> newfile.manage_edit( title=f.title, precondition=f.precondition,
> content_type=f.content_type )
> newfile.manage_upload( f.index_html( request, response ) )
> ###
>
--
David Chandek-Stark
dc at duke.edu
More information about the Zope-CMF
mailing list