[Grok-dev] Flash (ing) messages to user.
Christian Klinger
cklinger at novareto.de
Fri Aug 17 18:55:00 UTC 2012
Hello Christian,
i use a viewlet to display the error messages. This has the advantage
that i don't have to take care on every View if there is a flash message
or not.
Here is the viewlet:
class FlashMessages(grok.Viewlet):
grok.baseclass()
grok.order(200)
grok.context(Interface)
grok.name('uvcsite.messages')
grok.viewletmanager(IPageTop)
def update(self):
received = receive()
if received is not None:
self.messages = list(received)
else:
self.messages = []
and here the template for it.
<tal:messages tal:repeat="message viewlet.messages"
condition="viewlet.messages">
<div id="info-message" class="" tal:attributes="class message.type or
'info'">
<span tal:content="message.message" />
</div>
</tal:messages>
HTH Christian
Christian Schmidt schrieb:
> Hello Group,
>
> the grok.View.flash() method allows us to send short messages to the
> user. I.e. confirmation or error messages.
>
> after some hours of reading the sourcecode I found out how to get the
> messages displayed. Here is my solution:
>
> from grokcore.message.utils import receive
>
> ... view-class where the message is triggered:
>
> self.flash(u'this is my message')
>
> ... view-class where the message is displayed:
>
> self.messages = receive()
>
> ... template (similar to /grokui/base/templates/statusmessages.pt )
>
> <div class="notification">
> <dl>
> <dd tal:repeat="message view/messages"
> tal:attributes="class message/type"
> tal:content="message/message">notification goes here</dd>
> <dl>
> </div>
>
>
> my question. Is this the state of the art way to get messages displayed
> or is there any better solution?
>
> question to the core developers:
> why I am able to use flash as a View- method but for receiving messages
> I have to import the receive - method from the message - Package. -
> that's confusing - wouldn't it be better to make "receive()" a
> View-method too?
>
> regards
> Christian
More information about the Grok-dev
mailing list