changeset 31:4ac11f7992c6

index page now works and so does rss
author k0s <k0scist@gmail.com>
date Sun, 01 Nov 2009 01:28:23 -0400
parents 9be583a7731d
children 0826015cc13d
files bitsyblog/bitsyblog.py bitsyblog/templates/blog.html bitsyblog/templates/index.html
diffstat 3 files changed, 45 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Sat Oct 31 23:30:45 2009 -0400
+++ b/bitsyblog/bitsyblog.py	Sun Nov 01 01:28:23 2009 -0400
@@ -102,7 +102,8 @@
         request.environ['data'] = { 'site_name': self.site_name,
                                     'request': request,
                                     'link': self.link,
-                                    'logo': self.logo(request) }
+                                    'logo': self.logo(request),
+                                    'user_url': self.user_url }
 
         res = self.response_functions.get(request.method, self.error())(request)
         return res(environ, start_response)
@@ -226,9 +227,6 @@
             blog = list(reversed(blog))
 
         n_links = self.number_of_links(request, user)
-        # don't display navigation for short blogs
-        if len(blog) < 2:
-            n_links = 0
             
         # write the blog
         content = self.write_blog(user, blog, request.path_info, n_links, request)
@@ -519,29 +517,6 @@
 
     ### methods that write HTML
 
-    def render(self, request, body, title=None, feedtitle=None):
-        """layout the page in a unified way"""
-        _title = [ self.site_name ]
-        user = getattr(request, 'user', None)
-        if user:
-            stylesheets = request.user['CSS']
-            stylesheets = [ (("/%s" % self.user_url(request, user.name, 'css', css['filename'])),
-                             css['name']) for css in stylesheets ]
-            _title.insert(0, request.user.name)
-        else:
-            stylesheets = (("/css/site.css", "Default"),)
-            
-        if title:
-            _title.insert(0, title)
-            
-        title = ' - '.join(_title)
-        head_markup = ()
-        if feedtitle:
-            head_markup = ( '<link rel="alternate" type="application/atom+xml" title="%s" href="atom" />' % feedtitle, 
-                            '<link rel="alternate" type="application/rss+xml" title="%s" href="rss" />' % feedtitle,)
-        
-        return markup.wrap(self.site_nav(request)+body, title, stylesheets, head_markup=head_markup)
-
     def stylesheets(self, request):
         user = getattr(request, 'user', None)
         if user:
@@ -575,61 +550,28 @@
 
     def index(self, request, n_links):
         data = request.environ['data']
+        data['n_links'] = n_links
         self.site_nav(request)
+
+        # 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 latest active user first
+        users.sort(key=lambda user: blogs[user][0].date, reverse=True)
+
+        data['blogs'] = blogs
+        data['users'] = users
+        data['date_formats'] = dict([(user, self.users[user].settings.get('Date format', self.date_format)) for user in users])
+        
+        # render the template
         template = self.loader.load('index.html')
         return template.generate(**request.environ['data']).render()
 
-#         retval = StringIO()
-#         print >> retval, '<h1><img src="bitsyblog.png" alt="bitsyblog"/></h1>'
-
-#         # 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 latest active user first
-#         users.sort(key=lambda user: blogs[user][0].date, reverse=True)
-
-#         # 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
-        
-        if n_links == 0 or not len(blog):
-            return ''
-        retval = StringIO()
-        print >> retval, '<div class="navigation">'
-        more = ''
-        if (n_links != -1) and (len(blog) > n_links):
-            more = '<a href="%s?n=all">more</a>' % path
-            blog = blog[:n_links]
-
-        entries = []
-        for entry in blog:
-            blog_id = entry.datestamp()
-            format = prefs.get('Date format', self.date_format)
-            datestamp = entry.date.strftime(format)
-            synopsis = entry.title()
-            if synopsis:
-                synopsis = ': %s' % cgi.escape(synopsis)
-            entries.append(markup.link("%s#%s" % (path, blog_id), datestamp) + synopsis)
-
-        print >> retval, markup.listify(entries)
-        print >> retval, more
-        print >> retval, '</div>'
-        return retval.getvalue()
-
         
     def write_blog(self, user, blog, path, n_links, request):
         """return the user's blog in HTML"""
@@ -652,7 +594,6 @@
         data['stylesheets'] = self.stylesheets(request)
         data['subject'] = request.user.settings.get('Subject', self.subject)
         data['date_format'] = request.user.settings.get('Date format', self.date_format)
-        data['user_url'] = self.user_url
         data['mangledurl'] = self.mangledurl
 
         # blog data
@@ -739,11 +680,12 @@
         subject = prefs.get('Subject', self.subject)
         date_format = prefs.get('Date format', self.date_format)
         title = entry.title()
-        return PyRSS2Gen.RSSItem(title=title, #subject % { 'date': entry.date.strftime(date_format) },
-                                 link=self.permalink(entry),
+        link = self.permalink(request, entry)
+        return PyRSS2Gen.RSSItem(title=title, 
+                                 link=link,
                                  description=unicode(entry.body, errors='replace'),
                                  author=user,
-                                 guid=PyRSS2Gen.Guid(self.permalink(entry)),
+                                 guid=PyRSS2Gen.Guid(link),
                                  pubDate=entry.date)
 
 
@@ -791,7 +733,6 @@
         data = request.environ['data']
         data['user'] = user
         data['stylesheets'] = self.stylesheets(request)
-        data['user_url'] = self.user_url
 
         # render the template
         template = self.loader.load('post.html')
--- a/bitsyblog/templates/blog.html	Sat Oct 31 23:30:45 2009 -0400
+++ b/bitsyblog/templates/blog.html	Sun Nov 01 01:28:23 2009 -0400
@@ -24,7 +24,7 @@
     <!-- blog navigation -->
     <div class="navigation"
          py:if="n_links and len(blog) &gt; 1"
-         py:with="_n_links = (n_links != -1) and n_links or len(blog)">
+         py:with="_n_links = (n_links != -1) and min(n_links,len(blog)) or len(blog)">
       <ul>
         <li py:for="index in range(_n_links)"
             py:with="synopsis = blog[index].title()">
--- a/bitsyblog/templates/index.html	Sat Oct 31 23:30:45 2009 -0400
+++ b/bitsyblog/templates/index.html	Sun Nov 01 01:28:23 2009 -0400
@@ -12,5 +12,25 @@
     <xi:include href="navigation.html" />
     
     <h1 py:if="logo"><img src="${logo}" alt="${site_name}"/></h1>
+
+    <div py:for="user in users"
+         py:with="blog = blogs[user]; date_format = date_formats[user]"
+         class="user" id="${user}">
+
+      <a href="${user_url(request, user)}">${user}</a>
+
+      <div class="navigation"
+           py:if="n_links and len(blog) &gt; 1"
+           py:with="_n_links = (n_links != -1) and min(n_links,len(blog)) or len(blog)">
+        <ul>
+          <li py:for="index in range(_n_links)"
+              py:with="synopsis = blog[index].title()">
+            <a href="#${blog[index].datestamp()}">${blog[index].date.strftime(date_format)}</a><py:if test="synopsis">: ${synopsis}</py:if>
+          </li>
+        </ul>
+      </div>
+
+    </div>
+
   </body>
 </html>