Commits

Chris Miles committed b07ccbe

Implemented Flash messages using WebFlash.

Comments (0)

Files changed (8)

chronr/chronr/controllers/account.py

 import tw.forms
 
 from chronr.lib.base import BaseController, render
+from chronr.lib import helpers as h
 from chronr.model import User, UserActivation
 from chronr.model.meta import Session
 from chronr.model.forms.build import RegisterUserForm

chronr/chronr/controllers/home.py

 from pylons.controllers.util import abort, redirect_to
 
 from chronr.lib.base import BaseController, render
+from chronr.lib import helpers as h
 from chronr.lib.widgets.event_widgets import EventSummary, group_events
 from chronr.model import Event
 
         
         c.event_summary_widget = event_summary_widget
         c.grouped_events = group_events(events)
+        
+        # h.flash_alert("Foo Alert!")
+        # h.flash_info("Foo Info")
+        # h.flash_ok("Foo OK")
+        
         return render('/home.mako')
     
     def about(self):

chronr/chronr/lib/helpers.py

 #from webhelpers.html.tags import checkbox, password
 
 # from formbuild.helpers import field, start_with_layout as form_start, end_with_layout as form_end
-from pylons import url, request
+from pylons import url, request, response
 from routes.util import url_for
 # from webhelpers.html import literal
 # from webhelpers.html.tags import *
 
+from webflash import Flash
+
+
+flash = Flash(
+    get_response=lambda: response,
+    get_request=lambda: request
+)
+
+def flash_ok(message):
+    flash(message, status='ok')
+
+def flash_info(message):
+    flash(message, status='info')
+
+def flash_alert(message):
+    flash(message, status='alert')
+
 
 def user():
     """Return the currently logged-in user object

chronr/chronr/public/css/style.css

 
 
 /* TGPriFlash Classes */
-.flash_ok {
+
+#flash_container div.ok {
   margin: 0.5em auto 0.5em auto;
   padding: 15px 10px 15px 55px;
   width: 450px;
-  background: #cec URL('/static/images/flash_ok.png') left center no-repeat;
+  background: #cec URL('../images/flash_ok.png') left center no-repeat;
   border: 1px solid #9c9;
   font-size: 120%;
   font-weight: bolder;
   clear: both;
 }
 
-.flash_warning {
+#flash_container div.info {
   margin: 0.5em auto 0.5em auto;
   padding: 15px 10px 15px 55px;
   width: 450px;
-  background: #eef URL('/static/images/flash_info.png') left center no-repeat;
+  background: #eef URL('../images/flash_info.png') left center no-repeat;
   border: 1px solid #99c;
   font-size: 120%;
   font-weight: bolder;
   clear: both;
 }
 
-.flash_alert {
+#flash_container div.alert {
   margin: 0.5em auto 0.5em auto;
   padding: 15px 10px 15px 55px;
   width: 450px;
-  background: #fd9393 URL('/static/images/flash_alert.png') left center no-repeat;
+  background: #fd9393 URL('../images/flash_alert.png') left center no-repeat;
   border: 1px solid #e11;
   font-size: 120%;
   font-weight: bolder;
   float: left;
   margin-right: 1em;
   text-align: center;
-  background: white URL('/static/images/faintclock.png') center top no-repeat;
+  background: white URL('../images/faintclock.png') center top no-repeat;
   margin-bottom: 1em;
 }
 
 .welcome {
   color: #555;
   font-size: 95%;
-}
+}
+
+div.clearingdiv {
+  clear:both;
+}

chronr/chronr/templates/base/base-index.mako

     <span class="banner_text">Shared Event Engine</span>
   </div>  <!-- id="header" -->
 
+  <div class="clearingdiv" />
+  
+  ${h.flash.render("flash_container")|n}
+
   ${next.body()}
 
   <div id="footer">

chronr/data/templates/base/base-index.mako.py

 __M_dict_builtin = dict
 __M_locals_builtin = locals
 _magic_number = 5
-_modified_time = 1248701886.4342041
+_modified_time = 1249395771.021297
 _template_filename='/Users/chris/src/chronr-hg-rebuild_in_pylons/chronr/chronr/templates/base/base-index.mako'
 _template_uri='/base/base-index.mako'
 _template_cache=cache.Cache(__name__, _modified_time)
             __M_writer(escape(h.url_for()))
             __M_writer(u'">Login</a>\n')
         # SOURCE LINE 25
-        __M_writer(u'    </div>  <!-- id="user_login" -->\n    <span class="banner_text">Shared Event Engine</span>\n  </div>  <!-- id="header" -->\n\n  ')
-        # SOURCE LINE 29
+        __M_writer(u'    </div>  <!-- id="user_login" -->\n    <span class="banner_text">Shared Event Engine</span>\n  </div>  <!-- id="header" -->\n\n  <div class="clearingdiv" />\n  \n  ')
+        # SOURCE LINE 31
+        __M_writer(h.flash.render("flash_container"))
+        __M_writer(u'\n\n  ')
+        # SOURCE LINE 33
         __M_writer(escape(next.body()))
         __M_writer(u'\n\n  <div id="footer">\n    <p><a href="/about">About</a> | <a href="http://dev.chronr.com/">Developers</a></p>\n    <p>Copyright &copy; 2008-2009 <a href="http://chrismiles.info/">Chris Miles</a>. All rights reserved.</p>\n    <p>Version ?</p>\n  </div>  <!-- id="footer" -->\n\n  <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">\n  </script>\n  <script type="text/javascript">\n  _uacct = "UA-121474-5";\n  urchinTracker();\n  </script>\n</body>\n\n')
-        # SOURCE LINE 45
+        # SOURCE LINE 49
         __M_writer(u'\n')
         return ''
     finally:

chronr/development.ini

 qualname = chronr
 
 [logger_sqlalchemy]
-level = INFO
+level = WARNING
 handlers =
 qualname = sqlalchemy.engine
 # "level = INFO" logs SQL queries.
         "tw.forms",
         "TurboMail >= 3.0b2",
         "pytz",
+        "WebFlash",
     ],
     setup_requires=["PasteScript>=1.6.3"],
     packages=find_packages(exclude=['ez_setup']),