Zope Python Script Export all pages / documents to CSV

Need to export all your Plone pages / documents? This quick script will dump them all into a CSV for easy import into another system. You can add fields as needed.
from DateTime import DateTime

documents = context.portal_catalog.searchResults(portal_type = 'Document')

csv = 'Title,Created,Description,Text'

for document in documents:
	docObj = document.getObject()

	csv += '\n'
	csv += '"' + document.Title.decode('ascii', 'ignore').replace('"', '""') + '",'
	csv += '"' + DateTime(document['created']).strftime('%m-%d-%Y') + '",'
	csv += '"' + document.Description.decode('ascii', 'ignore').replace('"', '""') + '",'
	csv += '"' + docObj.getText().decode('ascii', 'ignore').replace('"', '""') + '",'

context.REQUEST.RESPONSE.setHeader('Content-type', 'text/csv')
context.REQUEST.RESPONSE.setHeader('Content-disposition','attachment; filename="documents.csv"')

return csv                  
Posted by
Snippet Viewed 1476 times.

Share your Zope Python Script code snippets:

  • Get some recognition & a link back to your site.
  • Create your own code library.
  • Help your fellow developers, as they have helped you.

 

Submit | Browse

Most Recent zope python snippets

Most Viewed