changeset 35:7e7fbdc64cc1

enable atom support, this brings us to 2.0
author k0s <k0scist@gmail.com>
date Sun, 01 Nov 2009 13:30:18 -0500
parents 2a43e43a7e4d
children 4b01f5bc84e6 695e59e5a4a7
files bitsyblog/bitsyblog.py bitsyblog/templates/atom.xml bitsyblog/templates/blog.html bitsyblog/templates/index.html bitsyblog/templates/site.html setup.py
diffstat 6 files changed, 59 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Sun Nov 01 01:51:14 2009 -0400
+++ b/bitsyblog/bitsyblog.py	Sun Nov 01 13:30:18 2009 -0500
@@ -25,14 +25,14 @@
 import PyRSS2Gen
 import re
 
-import utils # local import
+import utils 
 
 from blog import FileBlog
 from cStringIO import StringIO
 from docutils.utils import SystemMessage
 from genshi.builder import Markup
 from genshi.template import TemplateLoader
-from lxml import etree
+#from lxml import etree
 from markup.form import Form
 from paste.fileapp import FileApp
 from pkg_resources import resource_filename
@@ -98,12 +98,13 @@
     def __call__(self, environ, start_response):
         request = Request(environ)
 
-        # GENSHI: data dictionary
+        # genshi data dictionary
         request.environ['data'] = { 'site_name': self.site_name,
                                     'request': request,
                                     'link': self.link,
                                     'logo': self.logo(request),
-                                    'user_url': self.user_url }
+                                    'user_url': self.user_url,
+                                    'permalink': self.permalink }
 
         res = self.response_functions.get(request.method, self.error())(request)
         return res(environ, start_response)
@@ -394,7 +395,7 @@
         path = path[1:]
         if name:
             if name not in self.users:
-                exc.HTTPNotFound("No blog found for %s" % user)
+                exc.HTTPNotFound("No blog found for %s" % name)
             request.user = self.users[name]
         else:
             name = None
@@ -623,17 +624,17 @@
         retval = '<div class="blog-body">%s</div>' % body
         return retval
 
-        # this should be reenabled if 'system-message's again appear in the markup
-        try:            
-            foo = etree.fromstring(retval)
-        except etree.XMLSyntaxError:
-            return retval
-        # should cleanup the <div class="system-message">
-        for i in foo.getiterator():
-            if dict(i.items()).get('class') ==  'system-message':
-                i.clear()
+#         # XXX this should be reenabled if 'system-message's again appear in the markup
+#         try:            
+#             foo = etree.fromstring(retval)
+#         except etree.XMLSyntaxError:
+#             return retval
+#         # should cleanup the <div class="system-message">
+#         for i in foo.getiterator():
+#             if dict(i.items()).get('class') ==  'system-message':
+#                 i.clear()
                 
-        return etree.tostring(foo)
+#         return etree.tostring(foo)
 
 
     ### feeds
@@ -689,39 +690,18 @@
 
 
     def atom(self, request, blog, author=None):
-        retval = StringIO()
-        print >> retval, """<?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
-"""
-        if author:
-            title = "%s's blog" % author
-            link = request.host_url + '/' + author
-        else:
-            title = self.site_name + ' - atom'
-            link = request.application_url
-            
-        date = blog[0].date.isoformat()
 
-        print >> retval, '<title>%s</title>' % title
-        print >> retval, '<link href="%s" />' % link
-        print >> retval, '<updated>%s</updated>' % date
-        if author:
-            print >> retval, """
- <author>
-    <name>%s</name>
- </author>""" % author
- 
-        for entry in blog:
-            print >> retval, '<entry>'
-            print >> retval, '<title>%s</title>' % cgi.escape(entry.title())
-            print >> retval, '<link href="%s" />' % self.permalink(entry)
-            print >> retval, '<updated>%s</updated>' % entry.date.isoformat()
-            print >> retval, '<summary>%s</summary>' % cgi.escape(entry.body)
+        # data for genshi template
+        date = blog[0].date.isoformat()
+        data = request.environ['data']
+        data['blog'] = blog
+        data['author'] = author
+        data['date'] = date
 
-            print >> retval, '</entry>'
- 
-        print >> retval, '</feed>'
-        return retval.getvalue()
+        # render the template
+        template = self.loader.load('atom.xml')
+        return template.generate(**data).render()
+        
 
     ### forms
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitsyblog/templates/atom.xml	Sun Nov 01 13:30:18 2009 -0500
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom"
+      xmlns:py="http://genshi.edgewall.org/">
+
+  <py:choose test="bool(author)">
+    <py:when test="True">
+      <title>${author}'s blog</title>
+      <link href="${user_url(request, author)}"/>
+    </py:when>
+
+    <py:otherwise>
+      <title>${site_name} - atom</title>
+      <link href="${request.application_url}"/>
+    </py:otherwise>
+  </py:choose>
+
+  <updated>${date}</updated>
+
+  <entry py:for="entry in blog">
+    <title>${entry.title()}</title>
+    <link href="${permalink(request, entry)}"/>
+    <updated>${entry.date.isoformat()}</updated>
+    <summary>${entry.body}</summary>
+  </entry>
+</feed>
--- a/bitsyblog/templates/blog.html	Sun Nov 01 01:51:14 2009 -0400
+++ b/bitsyblog/templates/blog.html	Sun Nov 01 13:30:18 2009 -0500
@@ -8,6 +8,7 @@
   <head>
     <title>${user} - ${site_name}</title>
 
+    <!-- stylesheets -->
     <py:for each="index, (href, sheet) in enumerate(stylesheets)">
       <link href="${href}"
             type="text/css" 
@@ -15,8 +16,9 @@
             title="${sheet}"/>
     </py:for>
 
-    <link rel="alternate" type="application/rss+xml" title="blog - ${user}" href="${user_url(request, user, 'rss')}"/>
-
+    <!-- feeds -->
+    <link rel="alternate" type="application/rss+xml" title="blog - ${user} - RSS" href="${user_url(request, user, 'rss')}"/>
+    <link rel="alternate" type="application/atom+xml" title="blog - ${user} - Atom" href="${user_url(request, user, 'atom')}"/>
   </head>
 
   <body>
--- a/bitsyblog/templates/index.html	Sun Nov 01 01:51:14 2009 -0400
+++ b/bitsyblog/templates/index.html	Sun Nov 01 13:30:18 2009 -0500
@@ -7,8 +7,8 @@
   <head>
     <title>${site_name}</title>
     <link href="${link(request, 'css/site.css')}" type="text/css" rel="stylesheet" title="Default"/>
-    <link rel="alternate" type="application/rss+xml" title="${site_name}" href="${link(request, 'rss')}"/>
-
+    <link rel="alternate" type="application/rss+xml" title="${site_name} RSS" href="${link(request, 'rss')}"/>
+    <link rel="alternate" type="application/atom+xml" title="${site_name} Atom" href="${link(request, 'atom')}"/>
   </head>
   <body>
     <xi:include href="navigation.html" />
--- a/bitsyblog/templates/site.html	Sun Nov 01 01:51:14 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-<ul class="site-nav">
-  <li py:for="link_text, href in navigation">
-    <a href="${href}">${link_text}</a>
-  </li>
-</ul>
--- a/setup.py	Sun Nov 01 01:51:14 2009 -0400
+++ b/setup.py	Sun Nov 01 13:30:18 2009 -0500
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = '1.1.1'
+version = '2.0'
 
 try:
     description = file('README.txt').read()
@@ -33,10 +33,10 @@
           'python-dateutil',
           'markup',
           'skimpygimpy',
-          'lxml',
           'PyRSS2Gen',
           'docutils',
           'genshi',
+#          'lxml',
       ],
       dependency_links=[ 
         'https://svn.openplans.org/svn/standalone/markup#egg=markup',