Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1193 (closed enhancement: wontfix)

Opened 13 years ago

Last modified 10 years ago

Make tg_flash more style flexible

Reported by: allan.garcia Owned by: allangarcia
Priority: normal Milestone:
Component: TurboGears Version: 1.0b2
Severity: normal Keywords: tg_flash, flash, controllers


Make tg_flash more beautiful with turbogears.flash() method accepting two arguments:

  • first the message itself
  • second the name of the css style to show with

Change History

comment:1 Changed 13 years ago by allan.garcia

  • Status changed from new to assigned

comment:2 Changed 13 years ago by alberto

This  article might help.

comment:3 Changed 13 years ago by allangarcia

  • Owner changed from allan.garcia to allangarcia
  • Status changed from assigned to new

comment:4 Changed 13 years ago by allangarcia

  • Status changed from new to assigned

comment:5 Changed 13 years ago 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 @@

-    <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())" />

comment:6 Changed 13 years ago by alberto

  • Milestone changed from 1.0b2 to 1.1

comment:7 Changed 12 years ago by jorge.vargas

  • Milestone changed from 1.1 to 1.0.2

I like the idea, and the patch seems backward compatible. could we sneak this in 1.0.x?

comment:8 Changed 12 years ago by alberto

  • Milestone changed from 1.0.2 to __future__

I'm afraid the patch would only work in Genshi templates (look at the py:replace="ET(js.display())")

I'd rather not introduce this into 1.0.x... think "feature-freeze". However, I have something similar implemented as a widget, maybe I could factor it out from the app it lives in and release it as an EGG sometime.


comment:9 Changed 11 years ago by Chris Arndt

  • Status changed from assigned to closed
  • Resolution set to wontfix

This is supported by the  TurboFancyFlash package.

I think, it makes no sense to implement more features in turbogears.flash than it currently has, because everybody would have different requirements for flash messages, so this is better left to be provided by an external package.

comment:10 Changed 10 years ago by anonymous

  • Milestone __future__ deleted

Milestone future deleted

Note: See TracTickets for help on using tickets.