You are here: Home / Documentation / How To's / Script to export items in a folder

Script to export items in a folder

by nguyen — published Jan 13, 2014 05:35 PM, last modified Aug 16, 2016 10:50 AM

Why this script

The following script is useful when you are copying content from one Plone site to another, and you do not want to (or cannot) export entire folders at a time, which can happen if you have an add-on installed on the source site that is not installed on the destination site.  For example, some gallery add-ons add a marker interface to folder objects, and if you don't have those add-ons installed on the destination site, you will get an error when you try to import the whole folder.

What does it do

The script below creates a page containing links for each item in the folder. If you click on one of these links, it exports the item, leaving the exported .zexp on the server (as opposed to downloading it to your local computer).

Where to create the script

You can go to the folder's /manage_main URL and add a new Script (Python), or you can go to the site's portal_skins/custom/manage_main URL and add a new Script (Python) there.  If you create it in portal_skins/custom you will be able to invoke it from any folder in your site.

Call the new script something like .exportStuff and use the following code:

print '<p>Click on the following links to export each item:</p><ul>'
for itemTuple in context.items():
    (item, itemType) = itemTuple
    url = context.absolute_url() + '/manage_exportObject?id=%s' % item
    print '<li><a href="%s">%s</a></li>' % (url, item)

print "</ul>"
return printed

How to invoke the script

To invoke it, if you created it in portal_skins/custom, you would browse to the folder's URL with "/.exportStuff" appended, e.g. if you were trying to export items in http://mysite.com/folder then you would browse to http://mysite.com/folder/.exportStuff

If you created the script in the actual folder you want to export other items from, click the script's Test tab.  That will do the equivalent of browsing to http://mysite.com/folder/.exportStuff

What to do with the exported .zexp files

Once you've exported everything in the folder, the resulting zexp files are sitting in your Plone's var subdirectory on the server.

Copy them to the destination Plone's imports subdirectory using scp or Fugu or FileZilla.

Then on the destination Plone site, you can create the matching destination folder, then in that folder's /manage_main ZMI view, use the Import button to import each zexp.

 

Navigation