You are here: Home Blog Topics python scripts

python scripts

Aug 28, 2009

Migrating portal_status_message to addPortalMessage for Plone 3

by Chris Crownhart — last modified Aug 28, 2009 09:30 AM

Recently we did a large migration of a site with a high level of custom development. The old site was 2.0.5, and we migrated to 3.2.2. One of the coding changes we needed to make for the migration was fixing portal_status_message to use addPortalMessage.

This is a pretty simple change, but I could not find much documentation on it around the web.  We had quite a few controller python scripts that had code in them setting a portal_status_message.  The code looked like:

return state.set(portal_status_message='Your comment has been sent to the web support team.')

This old code is completely ignored now, so you have to convert these to the new format.

In Plone 3, portal_status_message is now handled using a cookie, and there are special classes and methods for adding your messages to the cookie.

Now, to set a status message, do the following:

from Products.CMFPlone import PloneMessageFactory as _
context.plone_utils.addPortalMessage(_(u'Your comment has been sent to the web support team.'))

Additionally, you can pass flags to the method to indicate:

  • 'info'
  • 'warning'
  • 'error'

like:

context.plone_utils.addPortalMessage(_(u'Your comment has been sent to the web support team.'), 'info')

For more information about the classes, interfaces, and methods, see this PLIP: http://plone.org/products/plone/roadmap/111

 
 
Copyright © 2003-2017 Core Software Group | 303/809-1001 | Fort Collins, Colorado | All rights reserved.