#1193: Make tg_flash more style flexible
------------------------------------------+---------------------------------
 Reporter:  allan.garcia                  |        Owner:  allangarcia
     Type:  enhancement                   |       Status:  assigned   
 Priority:  normal                        |    Milestone:  1.0b2      
Component:  TurboGears                    |      Version:  1.0b2      
 Severity:  normal                        |   Resolution:             
 Keywords:  tg_flash, flash, controllers  |  
------------------------------------------+---------------------------------
Comment (by allangarcia):

 my diff... I didn't know how to commit.

 {{{
 Index: turbogears/controllers.py
 ===================================================================
 --- turbogears/controllers.py   (revision 2191)
 +++ turbogears/controllers.py   (working copy)
 @@ -77,6 +77,9 @@
          tg_flash = _get_flash()
          if not tg_flash == None:
              output["tg_flash"] = tg_flash
 +        tg_flash_class = _get_flash_style()
 +        if not tg_flash_class == None:
 +            output["tg_flash_class"] = tg_flash_class
          output = view.render(output, template=template, format=format,
                      mapping=mapping,
 content_type=content_type,fragment=fragment)

 @@ -340,10 +343,11 @@
          template = func.__module__[:func.__module__.rfind('.')]+template
      return _process_output(output, template, format, content_type,
 mapping, fragment)

 -def flash(message):
 +def flash(message, style="flash"):
      """Set a message to be displayed in the browser on next page
 display."""
      cherrypy.response.simple_cookie['tg_flash'] =
 tg_util.to_utf8(message)
      cherrypy.response.simple_cookie['tg_flash']['path'] = '/'
 +    cherrypy.response.simple_cookie['tg_flash_class'] = style

  def _get_flash():
      """Retrieve the flash message (if one is set), clearing the
 message."""
 @@ -371,6 +375,32 @@
          message = unicode(message, 'utf-8')
      return message

 +def _get_flash_style():
 +    """Retrieve the flash message (if one is set), clearing the
 message."""
 +    request_cookie = cherrypy.request.simple_cookie
 +    response_cookie = cherrypy.response.simple_cookie
 +
 +    def clearcookie():
 +        response_cookie["tg_flash_class"] = ""
 +        response_cookie["tg_flash_class"]['expires'] = 0
 +        response_cookie['tg_flash_class']['path'] = '/'
 +
 +    if response_cookie.has_key("tg_flash_class"):
 +        style = response_cookie["tg_flash_class"].value
 +        response_cookie.pop("tg_flash_class")
 +        if request_cookie.has_key("tg_flash_class"):
 +            # New flash overrided old one sitting in cookie. Clear that
 old cookie.
 +            clearcookie()
 +    elif request_cookie.has_key("tg_flash_class"):
 +        style = request_cookie["tg_flash_class"].value
 +        if not response_cookie.has_key("tg_flash_class"):
 +            clearcookie()
 +    else:
 +        style = None
 +    if style:
 +        style = unicode(style, 'utf-8')
 +    return style
 +
  class Controller(object):
      """Base class for a web application's controller.

 Index: turbogears/qstemplates/quickstart/+package+/templates/master.html
 ===================================================================
 --- turbogears/qstemplates/quickstart/+package+/templates/master.html
 (revision 2191)
 +++ turbogears/qstemplates/quickstart/+package+/templates/master.html
 (working copy)
 @@ -32,7 +32,7 @@
          </span>
      </div>

 -    <div py:if="tg_flash" class="flash" py:content="tg_flash"></div>
 +    <div py:if="tg_flash" class="${tg_flash_class}"
 py:content="tg_flash"></div>
      <div py:for="js in tg_js_bodytop" py:replace="ET(js.display())" />
      <div py:replace="select('*|text()')" />
      <div py:for="js in tg_js_bodybottom" py:replace="ET(js.display())" />
 }}}

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/1193>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-tickets?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to