[Erp5-dev] proposed change of portal_status_message handling

Bartek Gorny bartek at gorny.edu.pl
Thu Jul 1 12:35:50 CEST 2010


The problem I see with the way status messages are sent to a user is
that the message is passed as GET parameter while redirecting - which
is a bit crude way and has many obvious limitations. I'd suggest to
add to in another option - to record messages in the user's selection
and erase while reading. Then, for backward compatibility, we can add
to it the standard portal_status_message and display a list of
messages. The advantange is that by doing this we can generate a
message on any stage of request processing - list method, interaction
workflow, wherever - and the message will eventually be delivered.
With a bit of extra coding we'd probably be able to produce this kind
of message from activities, if we want.

Here is the complete code:

SCRIPT: ERP5Site_sendUserMessage:
parameters: msg, translate=True

if translate:
  msg = context.Base_translateString(msg)

sname = 'user_message_selection'

params = context.portal_selections.getSelectionParamsFor(sname)
message_queue = params.get('message_queue', [])
message_queue.append(msg)
params['message_queue'] = message_queue
context.portal_selections.setSelectionParamsFor(sname, params)


SCRIPT: ERP5Site_getUserMessageList:

sname = 'user_message_selection'
params = context.portal_selections.getSelectionParamsFor(sname)
message_queue = params.get('message_queue', []) or []
params['message_queue'] = []
context.portal_selections.setSelectionParamsFor(sname, params)
return message_queue


SCRIPT: ERP5Site_getMessageList:

message_list = []
psm = context.REQUEST.get('portal_status_message', '')
if psm:
  message_list.append(psm)
r = context.ERP5Site_getUserMessageList()
message_list.extend(r)
return message_list


SCRIPT:ERP5Site_renderMessageList

message_list = context.ERP5Site_getMessageList()
if not message_list:
  return ''
if len(message_list) == 1:
  return message_list[0]
return context.render_message_list(message_list=message_list)

ZPT:render_message_list

<ul>
    <li tal:repeat="message options/message_list">
        <span tal:replace="message"></span>
    </li>
</ul>


And we can put into template_erp5_xhtml_style:
                <tal:block tal:define="message here/ERP5Site_renderMessageList">
                <div tal:condition="message">
                    <div  tal:content="structure message"
id="transition_message" />
                 </div>
                </tal:block>

Bartek

-- 
"CPU stepping is when you tile your front porch with extra CPU like
celeron 1ghz units.
typically you spread a thin layer of mortar the cpu's are laid and
then joints filled.
that's it cpu steps all done!"

(dragonsprayer at www.tomshardware.co.uk)



More information about the Erp5-dev mailing list