changeset 60:cf18ea0313f9

add some RSS
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 21 Nov 2010 17:00:02 -0800
parents 07cf168aa98c
children f5ca54558292
files decoupage/formats.py decoupage/utils.py setup.py
diffstat 3 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/formats.py	Sun Nov 21 13:23:34 2010 -0800
+++ b/decoupage/formats.py	Sun Nov 21 17:00:02 2010 -0800
@@ -2,6 +2,9 @@
 pluggable formats for directory listings
 """
 
+import datetime
+import PyRSS2Gen
+from utils import link
 try:
   import json as json
 except ImportError:
@@ -13,7 +16,7 @@
   just (basically) return the data
   """
 
-  def __init__(self, app, foo):
+  def __init__(self, app):
     self.app = app
 
   def __call__(self, request, data):
@@ -34,4 +37,16 @@
     self.cascade = cascade
 
   def __call__(self, request, data):
-    import pdb; pdb.set_trace()
+    items = [ PyRSS2Gen.RSSItem(title=item['name'],
+                                description=item['description'] or item['name'],
+                                pubDate=item['modified'],
+                                guid=PyRSS2Gen.Guid(link(request, item['path'])))
+              for item in data['files'] ]
+    path_link = link(request, data['path'])
+    rss = PyRSS2Gen.RSS2(title=data['title'] or data['path'],
+                         link=path_link,
+                         description=data['title'] or data['path'],
+                         lastBuildDate = datetime.datetime.now(),
+                         items=items
+                         )
+    return 'application/rss+xml', rss.to_xml()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/decoupage/utils.py	Sun Nov 21 17:00:02 2010 -0800
@@ -0,0 +1,9 @@
+def link(request, path):
+  """return a permalink"""
+  base_url = request.application_url.rstrip('/')
+  if not path:
+    return base_url + '/'
+  if not isinstance(path, basestring):
+    path = '/'.join(path)
+  return '%s/%s' % (base_url, path.lstrip('/'))
+  
--- a/setup.py	Sun Nov 21 13:23:34 2010 -0800
+++ b/setup.py	Sun Nov 21 17:00:02 2010 -0800
@@ -42,6 +42,7 @@
 
       [decoupage.formats]
       json = decoupage.formats:JSON
+      rss = decoupage.formats:RSS
 
       [decoupage.formatters]
       all = decoupage.formatters:All