Back to index

plone3  3.1.7
issueportalmessage.py
Go to the documentation of this file.
00001 from zope.deprecation import deprecate
00002 from kss.core.kssview import CommandSet
00003 
00004 from Products.statusmessages.message import Message
00005 
00006 # XXX: This is deprecated and will be removed in Plone 4.0. Use the 'plone'
00007 # command set instead.
00008 class IssuePortalMessageCommand(CommandSet):
00009 
00010     __allow_access_to_unprotected_subobjects__ = 1
00011 
00012     @deprecate("The 'portalmessage' command set is deprecated and will be removed in Plone 4.0. "
00013                "Please use the 'plone' command set instead.")
00014     def issuePortalMessage(self, message, msgtype='info'):
00015         'Issue this portal message'
00016         if message is None:
00017             # allow message = None.
00018             message = ''
00019 
00020         if isinstance(message, Message):
00021             msgtype = message.type
00022             message = message.message
00023 
00024         # XXX The macro has to take in account that there might be more than
00025         # one status message.
00026         ksscore = self.getCommandSet('core')
00027         selector = ksscore.getHtmlIdSelector('kssPortalMessage')
00028 
00029         # We hide the standard Plone Portal Message
00030         standar_portal_message_selector = ksscore.getCssSelector('.portalMessage')
00031         ksscore.setStyle(standar_portal_message_selector, 'display','none')
00032 
00033         # Now there is always a portal message but it has to be
00034         # rendered visible or invisible, accordingly
00035         html = '<dt>%s</dt><dd>%s</dd>' % (msgtype, message)
00036         ksscore.replaceInnerHTML(selector, html)
00037         ksscore.setAttribute(selector, 'class', "portalMessage %s" % msgtype)
00038         ksscore.setStyle(selector, 'display', message and 'block' or 'none')