You are here: Home / Documentation / How To's / Script to convert Quills blog posts to Plone pages ("Documents")

Script to convert Quills blog posts to Plone pages ("Documents")

by nguyen — published Nov 30, 2013 08:45 PM, last modified Aug 16, 2016 10:50 AM

In the ZMI add a Script (Python) called ".convert" with this code:

# Example code:

# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE

#return "container is ", container.id

# # Return a string identifying this script.
# print "This is the", script.meta_type, '"%s"' % script.getId(),
# if script.title:
#     print "(%s)" % html_quote(script.title),
# print "in", container.absolute_url()

#print container.contentItems()
#print [i for i in container.contentItems() if i[1].meta_type == 'WeblogEntry']
#blog_entries = [i for i in container.contentItems() if i[1].meta_type == 'WeblogEntry']
#print len([i for i in container.contentItems() if i[1].meta_type == 'WeblogEntry'])

#container.invokeFactory("ATFolder", id="newblog")
newblog = container['newblog']


#return blog_entries[0]

for blogentry_tuple in [i for i in container.contentItems() if i[1].meta_type == 'WeblogEntry']:
    blogentry = blogentry_tuple[1]
    #print "blog entry '", blogentry.id, "'has title '", blogentry.Title(), "', summary '", blogentry.description(), "', body '", blogentry.getText(), "', keywords '", blogentry.Subject(), "', contributors '", blogentry.Contributors(), "', creators '", blogentry.Creators(), "', effective date ", blogentry.getEffectiveDate(), "', creation date ", blogentry.created(), "', last modification date ", blogentry.modified(), "', expiration date ", blogentry.getExpirationDate()
    newblog.invokeFactory("Document", id=blogentry.id, title=blogentry.Title())
    newblogentry = newblog[blogentry.id]
    newblogentry.setDescription(blogentry.description())
    newblogentry.setText(blogentry.getText())
    newblogentry.setSubject(blogentry.Subject())
    newblogentry.setContributors(blogentry.Contributors())
    newblogentry.setCreators(blogentry.Creators())
    newblogentry.setEffectiveDate(blogentry.getEffectiveDate())
    newblogentry.setCreationDate(blogentry.created())
    newblogentry.setModificationDate(blogentry.modified())
    newblogentry.setExpirationDate(blogentry.getExpirationDate())
    print "blog entry '", blogentry.id, "'has title '", blogentry.Title(), "' converted"
#    return printed

return printed
 

Before Running the Script

Before you run it, create a sibling Folder with ID "newblog".  The script will create a Plone Document with the same ID, title, and other metadata for each Quills WeblogEntry object in the current folder.

After Running the Script

Export and Import

You can then use the ZMI to export the "newblog" folder and import the resulting "newblog.zexp" into another site.  

You may also want to export the "uploads" and "topic_images" folders in the Quills blog folder and import those into the new site's "newblog" folder.

Migrate BTrees

On the destination site, you may need to run the "/@@migrate-btrees" view to convert Plone 3.x ATFolder objects to the new BTree ATFolder in Plone 4.x. 

Reindex Catalog

On the destination site you will also want to go to the ZMI -> portal_catalog -> Advanced tab -> Clear and Rebuild button to index the new pages.

Publish All the Converted Pages

If you want to publish all the converted pages ("Documents"), you can run the companion Script to publish all pages in a folder

Navigation