changeset 628:693a7212b348

GenshiTutorial: tweaks to sync with code on wiki page.
author cmlenz
date Mon, 03 Sep 2007 19:59:03 +0000
parents 2f4dc32a13e7
children cae74e2637c6
files examples/tutorial/geddit/controller.py examples/tutorial/geddit/templates/index.html examples/tutorial/geddit/templates/index.xml examples/tutorial/geddit/templates/info.html examples/tutorial/geddit/templates/submit.html
diffstat 5 files changed, 30 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/examples/tutorial/geddit/controller.py
+++ b/examples/tutorial/geddit/controller.py
@@ -1,9 +1,6 @@
 #!/usr/bin/env python
 
-import operator
-import os
-import pickle
-import sys
+import operator, os, pickle, sys
 
 import cherrypy
 from formencode import Invalid
@@ -20,18 +17,6 @@
         self.data = data
 
     @cherrypy.expose
-    @template.output('index.xml', method='xml')
-    def feed(self, id=None):
-        if id:
-            link = self.data.get(id)
-            if not link:
-                raise cherrypy.NotFound()
-            return template.render('info.xml', link=link)
-        else:
-            links = sorted(self.data.values(), key=operator.attrgetter('time'))
-            return template.render(links=links)
-
-    @cherrypy.expose
     @template.output('index.html')
     def index(self):
         links = sorted(self.data.values(), key=operator.attrgetter('time'))
@@ -92,6 +77,18 @@
             stream = template.render(link=link, comment=None, errors=errors)
         return stream | HTMLFormFiller(data=data)
 
+    @cherrypy.expose
+    @template.output('index.xml', method='xml')
+    def feed(self, id=None):
+        if id:
+            link = self.data.get(id)
+            if not link:
+                raise cherrypy.NotFound()
+            return template.render('info.xml', link=link)
+        else:
+            links = sorted(self.data.values(), key=operator.attrgetter('time'))
+            return template.render(links=links)
+
 
 def main(filename):
     # load data from the pickle file, or initialize it to an empty list
@@ -113,7 +110,7 @@
             fileobj.close()
     cherrypy.engine.on_stop_engine_list.append(_save_data)
 
-    # Some global configuration; note that this could be moved into a 
+    # Some global configuration; note that this could be moved into a
     # configuration file
     cherrypy.config.update({
         'request.throw_errors': True,
--- a/examples/tutorial/geddit/templates/index.html
+++ b/examples/tutorial/geddit/templates/index.html
@@ -5,17 +5,24 @@
   <xi:include href="layout.html" />
   <head>
     <title>News</title>
+    <link rel="alternate" type="application/atom+xml" title="Geddit"
+          href="${url('/feed/')}" />
   </head>
   <body>
     <h1>News</h1>
 
-    <ol py:if="links">
+    <ol py:if="links" class="links">
       <li py:for="link in links">
         <a href="${link.url}">${link.title}</a>
         posted by ${link.username} at ${link.time.strftime('%x %X')}
+        <div class="info">
+          <a href="${url('/info/%s/' % link.id)}">
+            ${len(link.comments)} comments
+          </a>
+        </div>
       </li>
     </ol>
 
-    <p><a class="action" href="/submit/">Submit new link</a></p>
+    <p><a class="action" href="${url('/submit/')}">Submit new link</a></p>
   </body>
 </html>
--- a/examples/tutorial/geddit/templates/index.xml
+++ b/examples/tutorial/geddit/templates/index.xml
@@ -2,7 +2,7 @@
 <feed xmlns="http://www.w3.org/2005/Atom"
       xmlns:py="http://genshi.edgewall.org/">
 
-  <title>Geddit</title>
+  <title>Geddit News</title>
   <id href="${url('/')}"/>
   <link rel="alternate" href="${url('/')}" type="text/html"/>
   <link rel="self" href="${url('/feed/')}" type="application/atom+xml"/>
--- a/examples/tutorial/geddit/templates/info.html
+++ b/examples/tutorial/geddit/templates/info.html
@@ -5,8 +5,8 @@
   <xi:include href="layout.html" />
   <head>
     <title>${link.title}</title>
-    <link rel="alternate" title="Geddit: ${link.title}"
-          type="application/atom+xml" href="${url('/feed/%s/' % link.id)}" />
+    <link rel="alternate" type="application/atom+xml" title="Geddit: ${link.title}"
+          href="${url('/feed/%s/' % link.id)}" />
     <script type="text/javascript">
       function loadCommentForm(a) {
         $.get("${url('/comment/%s/' % link.id)}", {}, function(html) {
@@ -29,9 +29,7 @@
                   if ($("ul.comments").length == 0) {
                     a.parent().before('<ul class="comments"></ul>');
                   }
-                  $("ul.comments")
-                    .find("li.hilite").removeClass("hilite").end()
-                    .append($(elem).addClass("hilite")).slideDown();
+                  $("ul.comments").append($(elem));
                   closeForm();
                 }
               });
@@ -59,6 +57,6 @@
           py:for="num, comment in enumerate(link.comments)" />
     </ul>
 
-    <p><a class="action" href="${url('/comment/%s/' % link.id)}">comment</a></p>
+    <p><a class="action" href="${url('/comment/%s/' % link.id)}">Add comment</a></p>
   </body>
 </html>
--- a/examples/tutorial/geddit/templates/submit.html
+++ b/examples/tutorial/geddit/templates/submit.html
@@ -8,6 +8,7 @@
   </head>
   <body>
     <h1>Submit new link</h1>
+
     <form action="" method="post">
       <table summary=""><tbody><tr>
         <th><label for="username">Your name:</label></th>
@@ -35,5 +36,6 @@
         </td>
       </tr></tbody></table>
     </form>
+
   </body>
 </html>
Copyright (C) 2012-2017 Edgewall Software