# HG changeset patch # User Jeff Hammel # Date 1290387602 28800 # Node ID cf18ea0313f98c95a7f870713187280b559f5bbf # Parent 07cf168aa98ccab9512223cc4a4195066b598803 add some RSS diff -r 07cf168aa98c -r cf18ea0313f9 decoupage/formats.py --- 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() diff -r 07cf168aa98c -r cf18ea0313f9 decoupage/utils.py --- /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('/')) + diff -r 07cf168aa98c -r cf18ea0313f9 setup.py --- 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