Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion Important! Update your TG2 apps [WAS:] Re-implement flash without sessions
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alberto Valverde  
View profile  
 More options Jan 18 2009, 1:12 pm
From: Alberto Valverde <albe...@toscat.net>
Date: Sun, 18 Jan 2009 19:12:45 +0100
Local: Sun, Jan 18 2009 1:12 pm
Subject: Important! Update your TG2 apps [WAS:] Re-implement flash without sessions

Jorge Vargas wrote:
>> If someone wants to cook a widget or something for this or add a config
>> option so TG can use one or the other or something the community will
>> appreciate it (hint, Jorge, hint ;)

> Ok I will :) But I can't promise I could get some time before b3, it
> seems we are going to have b4 so I don't see this as a problem (nor a
> blocker), of course for this to work what you say below has to be
> implemented, which I'm +1

Nevermind, I already implemented a helper :) read below...

>> One more thing: I'd finally like to change the DOM structure and CSS of
>> the quickstart template to match the structure generated by the JS
>> version. Mainly so both versions can be used interchangeably and because
>> the current one sucks ;)  Why? Because:

>> 1) The class of  the message should be conveyed in a... class attribute.
>> The current implementation makes impossible to refer to the *unique* div
>> that holds the flash in a reliable way from JS code. The id should
>> remain static, the class should vary with the kind of message (not the
>> other way around)

>> 2) If the flash message is wrapped in a div inside the "flash" div then
>> one can implement floating centered messages easily.

>> To make it easy to visualize, the dom structure that the js code
>> generates is like this:

>> <div id="some_id_of_your_liking">
>>    <div class="status_code">Message</div>
>> </div>

>> So the CSS style this could be something like:

>> #some_id_of_your_liking {
>>    display: none;  /* Recommended so a conditional can be avoided, the
>> JS code will make it visible */
>>    ...
>> }

>> #some_id_of_your_liking .ok { ....}
>> #some_id_of_your_liking .warn { ....}
>> #some_id_of_your_liking .error { ....}

>> Please strip the status_X prefix from the status code names, it is
>> redundant to say:

>> flash("lalalala", status="status_ok")
>> much nicer (IMHO) and less typing (mathematically provable):
>> flash("lalala", status="ok")

>> If no one object I'll implement these *slightly* breaking changes (for
>> existing users) tomorrow. Note that the default will still be non-js
>> flash messages, I'm just proposing to change the dom structure and CSS
>> to keep both in sync so it is easy to change between them.

Done in:

http://trac.turbogears.org/changeset/6114
http://trac.turbogears.org/changeset/6115
http://trac.turbogears.org/changeset/6116
http://trac.turbogears.org/changeset/6117

The quickstart template has been updated to the new DOM structure and
existing apps should continue working but show deprecation warnings.

How to upgraded your existsing apps (the following instructions could be
copy and pasted somewhere in the CHANGELOG)

1) The flash message is now rendered like this (in a genshi template)

<py:with vars="flash=tg.flash_obj.render('flash', use_js=False)">
    <div py:if="flash" py:content="XML(flash)" />
</py:with>

Note that the tg.flash_obj.render() method returns a string so we need
to use the XML wrapper (not the HTML!) so genshi doesn't escape the html
entities. The conditional is so XML doesn't barf when there's no flash
(and we're not using JS) since render() will return an empty string.

To enable JS flash messages and be able to cache your pages just pass
use_js=True to the render() method

1.5) Using the helper in string based templates is easier, just do:

${tg.flash_obj.render('flash', use_js=False)}

2) Upgrade the your CSS to the new DOM structure, which is:

<div ="$flash_id">
    <div class="$status">$message</div>
</div>

The one in the quickstart template looks like:

#flash {
font-size:120%;
font-weight:bolder;
margin:0pt auto 0.5em;
width:680px;

}

#flash div {
padding:5px 15px 15px 55px;
}

#flash .ok {
background:#EEEEFF url(../images/ok.png) no-repeat scroll left center;
border:1px solid #CCCCEE;
}

#flash .warning {
background:#FF9999 url(../images/error.png) no-repeat scroll left center;
border:1px solid #FF3333;
}

#flash .alert {
background:#FFFF99 url(../images/info.png) no-repeat scroll left center;
border:1px solid #FFFF00;

}

3) Change your code so the status string you pass to flash() does not
contain the "status_" prefix, eg:

status_ok -> ok
status_warning -> warning
status_alert -> alert

This step might not be needed if you use custom status codes

The tg.flash and tg.flash_status variables in the template have been
deprecated, the equivalents are tg.flash_obj.status and
tg.flash_obj.message. Note that any access to these will remove the
cookie so do not access them if using JS to render the messages.

Enjoy,
Alberto


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.