changeset 89:7f7f7313b4c4

add html to rss feeds
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 17 Nov 2011 16:06:23 -0800
parents a3a7ac9102dc
children d29100da202a
files bitsyblog/bitsyblog.py setup.py
diffstat 2 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Thu Nov 17 15:18:13 2011 -0800
+++ b/bitsyblog/bitsyblog.py	Thu Nov 17 16:06:23 2011 -0800
@@ -53,7 +53,8 @@
                  'auto_reload': True, # reload the genshi templates
                  'help_file': None, # help to display
                  'feed_items': 10, # number of RSS/atom items to display
-                 'post_handlers': '' # post handlers
+                 'post_handlers': '', # post handlers
+                 'rss_html': True, # whether to render rss descriptions as HTML
                  }
 
     cooked_bodies = {}
@@ -73,7 +74,6 @@
                     kw_value = _type(kw_value)
             setattr(self, key, kw_value)
 
-        self.n_links = int(self.n_links) # could be a string from the .ini
         self.response_functions = {'GET': self.get,
                                    'POST': self.post,
                                    'PUT': self.put
@@ -81,11 +81,9 @@
 
         # abstract attributes
         from user import FilespaceUsers
-
         self.users = FilespaceUsers(self.file_dir)
         self.blog = FileBlog(self.file_dir)
         self.cooker = self.restructuredText
-        self.feed_items = int(self.feed_items)
 
         # template renderer
         self.template_directories = self.template_directories.split() # no spaces in directory names, for now
@@ -687,7 +685,6 @@
 #         for i in foo.getiterator():
 #             if dict(i.items()).get('class') ==  'system-message':
 #                 i.clear()
-                
 #         return etree.tostring(foo)
 
 
@@ -696,11 +693,11 @@
     def site_rss(self, request, n_items=10):
         blog = self.blog.latest(list(self.users.users()), n_items)
         title = self.site_name + ' - rss'
-        link = request.application_url 
+        link = request.application_url
         description = "latest scribblings on %s" % self.site_name
         lastBuildDate = datetime.datetime.now()
         items = [ self.rss_item(request, entry.user, entry) for entry in blog ]
-        rss = PyRSS2Gen.RSS2(title=title, 
+        rss = PyRSS2Gen.RSS2(title=title,
                              link=link,
                              description=description,
                              lastBuildDate=lastBuildDate,
@@ -712,14 +709,14 @@
         rss feed for a user's blog
         done with PyRSS2Gen:
         http://www.dalkescientific.com/Python/PyRSS2Gen.html
-        """        
+        """
         title = "%s's blog" % user
         link = os.path.split(request.url)[0]
         description = "latest blog entries for %s on %s" % (user, self.site_name)
         lastBuildDate = datetime.datetime.now() # not sure what this means
-        
+
         items = [ self.rss_item(request, user, entry) for entry in blog ]
-        rss = PyRSS2Gen.RSS2(title=title, 
+        rss = PyRSS2Gen.RSS2(title=title,
                              link=link,
                              description=description,
                              lastBuildDate=lastBuildDate,
@@ -735,9 +732,17 @@
         date_format = prefs.get('Date format', self.date_format)
         title = entry.title()
         link = self.permalink(request, entry)
-        return PyRSS2Gen.RSSItem(title=title, 
+
+        # item description
+        if self.rss_html:
+            body = self.cooked_entry(entry)
+        else:
+            body = entry.body
+            body = unicode(body, errors='replace')
+
+        return PyRSS2Gen.RSSItem(title=title,
                                  link=link,
-                                 description=unicode(entry.body, errors='replace'),
+                                 description=body,
                                  author=user,
                                  guid=PyRSS2Gen.Guid(link),
                                  pubDate=entry.date)
@@ -755,7 +760,7 @@
         # render the template
         template = self.loader.load('atom.xml')
         return template.generate(**data).render()
-        
+
 
     ### forms
 
--- a/setup.py	Thu Nov 17 15:18:13 2011 -0800
+++ b/setup.py	Thu Nov 17 16:06:23 2011 -0800
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = '2.4'
+version = '2.4.1'
 
 try:
     description = file('README.txt').read()