changeset 20:1554cb56aa2f

got index working, just doesnt do anything
author k0s <k0scist@gmail.com>
date Sun, 25 Oct 2009 21:36:33 -0400
parents 8931c5b7e632
children 7cdb3eecc045
files bitsyblog/bitsyblog.py bitsyblog/templates/index.html
diffstat 2 files changed, 46 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Sun Oct 25 21:30:42 2009 -0400
+++ b/bitsyblog/bitsyblog.py	Sun Oct 25 21:36:33 2009 -0400
@@ -106,6 +106,12 @@
         res = Response(content_type=content_type, body=text)
         return res
 
+    def logo(self, request):
+        _logo = 'bitsyblog.png' # TODO: should go to self.logo 
+        logo = os.path.join(self.file_dir, _logo)
+        if os.path.exists(logo):
+            return self.link(request, _logo)
+
     def get_index(self, request):
         """returns material pertaining to the root of the site"""
 
@@ -114,7 +120,7 @@
 
         ### the front page
         if not path:
-            return self.get_response(self.index(n_links))
+            return self.get_response(self.index(request, n_links))
 
         ### feeds
 
@@ -146,7 +152,7 @@
         # logo
         if path == 'bitsyblog.png':
             logo = os.path.join(self.file_dir, 'bitsyblog.png')
-            if not os.path.exists(logo):
+            if not self.logo(request):
                 raise exc.HTTPNotFound
             return self.get_response(file(logo, 'rb').read(), content_type='image/png') # should use FileApp
 
@@ -233,7 +239,7 @@
         request.environ['data'] = { 'site_name': self.site_name,
                                     'request': request,
                                     'link': self.link,
-                                    'escape': cgi.escape }
+                                    'logo': self.logo(request) }
 
         # front matter of the site
         index = self.get_index(request)
@@ -552,7 +558,7 @@
         user = self.authenticated(request)
         if user:
             links.extend([(self.user_url(request, user), user),
-                          (self.user_url(request, user, 'post'), user),
+                          (self.user_url(request, user, 'post'), 'post'),
                           (self.user_url(request, user, 'preferences'), 'preferences'),
                           (self.link(request, 'logout'), 'logout')])
         else:
@@ -566,30 +572,34 @@
 
 
     def index(self, request, n_links):
-        
-        retval = StringIO()
-        print >> retval, '<h1><img src="bitsyblog.png" alt="bitsyblog"/></h1>'
+        data = request.environ['data']
+        self.site_nav(request)
+        template = self.loader.load('index.html')
+        return template.generate(**request.environ['data']).render()
 
-        # get the blogs
-        blogs = {}
-        for user in self.users:
-            blog = self.blog(user, ('public',), n_links)
-            if blog:
-                blogs[user] = blog
-        users = blogs.keys()
+#         retval = StringIO()
+#         print >> retval, '<h1><img src="bitsyblog.png" alt="bitsyblog"/></h1>'
 
-        # display latest active user first
-        users.sort(key=lambda user: blogs[user][0].date, reverse=True)
+#         # get the blogs
+#         blogs = {}
+#         for user in self.users:
+#             blog = self.blog(user, ('public',), n_links)
+#             if blog:
+#                 blogs[user] = blog
+#         users = blogs.keys()
 
-        # display users' blogs
-        for user in users:
-            print >> retval, '<div id="%s" class="user">' % user
-            print >> retval, '<a href="%s">%s</a>' % (user, user)
-            blog = blogs[user]
-            print >> retval, self.navigation(user, blog, '/%s' % user, n_links)
-            print >> retval, '</div>'
+#         # display latest active user first
+#         users.sort(key=lambda user: blogs[user][0].date, reverse=True)
 
-        return self.render(request, retval.getvalue(), feedtitle=self.site_name)
+#         # display users' blogs
+#         for user in users:
+#             print >> retval, '<div id="%s" class="user">' % user
+#             print >> retval, '<a href="%s">%s</a>' % (user, user)
+#             blog = blogs[user]
+#             print >> retval, self.navigation(user, blog, '/%s' % user, n_links)
+#             print >> retval, '</div>'
+
+#         return self.render(request, retval.getvalue(), feedtitle=self.site_name)
 
     def navigation(self, user, blog, path, n_links, n_char=80):
         prefs = self.users[user].settings
@@ -848,7 +858,7 @@
         request.environ['data'] = { 'site_name': self.site_name,
                                     'request': request,
                                     'link': self.link,
-                                    'escape': cgi.escape }
+                                    'logo': self.logo(request) }
 
         ### user space
         user, path = self.userpath(request)
--- a/bitsyblog/templates/index.html	Sun Oct 25 21:30:42 2009 -0400
+++ b/bitsyblog/templates/index.html	Sun Oct 25 21:36:33 2009 -0400
@@ -1,8 +1,16 @@
-<html>
+<!DOCTYPE html
+    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
   <head>
+    <title>${site_name}</title>
+    <link href="${link(request, 'css/site.css')}" type="text/css" rel="stylsheet" title="Default"/>
   </head>
   <body>
-    <xi:include href="site.html" />
-    <h1><img src="bitsyblog.png" alt="${site_name}"/></h1>
+    <xi:include href="navigation.html" />
+    
+    <h1 py:if="logo"><img src="${logo}" alt="${site_name}"/></h1>
   </body>
 </html>