On Wed, Dec 29, 2010 at 1:28 PM, Marius Gedminas <mar...@gedmin.as> wrote:
> On Wed, Dec 29, 2010 at 10:56:29AM -0800, Seth wrote:
> The docs say that messages don't have to be strings, so you can do
> exactly that, if you push dicts like this:
>
>  request.session.flash(dict(message='Hello!', queue='welcome')).
>
> Or you could push tuples.  Or a custom subclass of unicode with a
> 'css_class' attribute -- just make sure it's pickleable.

Hi there. I wrote the flash code for WebHelpers, then somebody (I
can't remember who) asked for categories and we expanded it, then I
adapted it forPyramid's central session object, and Chris modified it
to the current version. It has multiple queues because the WebHelpers
concept of multiple Flash objects is non-viable with the flash
integrated into he session. I initially kept categories, but then
Chris and I decided to drop them because queues cover almost the same
purpose. The only thing you can't do without categories is to mix them
(i.e., display an INFO then DEBUG then ERROR then INFO, in whatever
order the messages were pushed). It seemed unlikely people would want
to do that anyway for web display; rather they'd want to show all the
errors first, then the infos, then the debugs, which you can do with
multiple queues.

The messages are intended to be strings, but this is not enforced. I
couldn't think of any specific use case for non-string messages, but
users always come up with unanticipated uses so I didn't want to
prevent those. (Queue names have to be strings because they're
concatenated to a constant string to create a session key.)

If there's a need for additional features, we can consider adding
them. I'm not sure what Seth is asking. "a method which returns *any*
flash message from any queue". So you want the messages returned in
creation order tagged with their queue name? This would be the same as
"categories" which I described above, which is not implemented because
it seemed like too much complexity for too little value. It sounds
like Marius' suggestion is a suitable workaround, using one queue and
pushing an object that contains both a message and a category. I think
you can build a higher-level API to make that convenient. If you need
some kind of helper method or something in the core, let us know and
we'll consider it.

PS. Chris added the '.peek_flashes' method. I didn't see the use for
it, but again it's there for unanticipated use cases. I usually do "if
peek_flashes; for msg in pop_flashes" as "<% messages =
request.session.pop_flashes() %>  %if messages:" .

-- 
Mike Orr <sluggos...@gmail.com>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-de...@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to