Commits

Anonymous committed 24bb4d9

Add "flash message" demo to default home page.

Comments (0)

Files changed (5)

 
   + Simplify home page and add a Mako site template that can be easily
     extended by the user.
+  + Add "flash message" demo to home page.
 
 1.0b2 (2011-03-19)
 ------------------

akhet/paster_templates/akhet/+package+/handlers/main.py_tmpl

 class Main(base.Handler):
     @action(renderer="index.html")
     def index(self):
+        # Do some logging.
         log.debug("testing logging; entered Main.index()")
+
+        # Push a flash message if query param 'flash' is non-empty.
+        if self.request.params.get("flash"):
+            import random
+            num = random.randint(0, 999999)
+            message = "Random number of the day is:  %s." % num
+            self.request.session.flash(message)
+            # Normally you'd redirect at this point but we have nothing to
+            # redirect to.
+
+        # Return a dict of template variables for the renderer.
         return {"project":"{{project}}"}
+        

akhet/paster_templates/akhet/+package+/static/stylesheets/default.css

 body {
-    font-family: sans-serif;
+    font-family: helvetica, verdana, sans-serif;
     }
 
 a {
 h1#title {
     text-align: center;
     }
+
+div#flash-messages {
+    }
+
+.info {
+    background-color: #54ff95;  /* SeaGreen1 */
+    font-size: larger;
+    font-style: italic;
+    margin: 10px 80px;
+    padding: 10px;
+    }

akhet/paster_templates/akhet/+package+/templates/index.html

   framework, part of the Pylons Project.
 </p>
 
-<h2>Search Pyramid documentation</h2>
-<form method="get" action="http://docs.pylonshq.com/pyramid/dev/search.html">
-  <div>
-    <input type="text" id="q" name="q" value="" />
-    <input type="submit" id="x" value="Search" />
-  </div>
-</form>
+<p><a href="${url.app}?flash=1">Display a flash message.</a></p>
 
 <h2>Pyramid links</h2>
 <ul>
   <li>
       <a href="irc://irc.freenode.net#pyramid">IRC Channel</a>
   </li>
+</ul>
+
+
+<h2>Search Pyramid documentation</h2>
+<form method="get" action="http://docs.pylonshq.com/pyramid/dev/search.html">
+  <div>
+    <input type="text" id="q" name="q" value="" />
+    <input type="submit" id="x" value="Search" />
+  </div>
+</form>
+

akhet/paster_templates/akhet/+package+/templates/site.html

       <h1 id="title">${self.body_title()}</h1>
     </div>
 
+<div id="flash-messages">
+% for message in request.session.pop_flash():
+    <div class="info">${message}</div>
+% endfor
+</div>
 
 <!-- *** BEGIN page content *** -->
 ${self.body()}