You are here: Home Blog Migrating portal_status_message to addPortalMessage for Plone 3

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

Document Actions

Should the text of messages really be set in the code?

Avatar Posted by catherine_w at Jan 28, 2010 02:16 PM
This is great, but arguably we should go a step further and enable site administrators who aren't python programmers to choose what text gets displayed to site users. Here we have the text of an important user-facing message sitting in code, rather than in some kind of interface that is accessible to the content strategist or information architect. The need to dig deeply into code to make minor tweaks to the user interface is one of Plone's achilles heels.

Add comment

You can add a comment by filling out the form below. Plain text formatting.

Info
You are not logged in. You may optionally enter your username and password below. If you don't enter anything, this comment will be posted as 'Anonymous User'.
(Required)
(Required)
(Required)
Enter the word
 
 
Copyright © 2003-2017 Core Software Group | 303/809-1001 | Fort Collins, Colorado | All rights reserved.