Created
June 19, 2014 02:06
-
-
Save dstegelman/b3f64f446591bef7912a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.serializers import Serializer | |
import datetime | |
from django.utils import feedgenerator | |
class RSSSerializer(Serializer): | |
formats = ['json', 'jsonp', 'xml', 'yaml', 'html', 'plist', 'rss'] | |
content_types = { | |
'json': 'application/json', | |
'jsonp': 'text/javascript', | |
'xml': 'application/xml', | |
'yaml': 'text/yaml', | |
'html': 'text/html', | |
'plist': 'application/x-plist', | |
'rss': 'application/rss+xml', | |
} | |
def to_rss(self, data, options=None): | |
options = options or {} | |
rss_items = [] | |
data = self.to_simple(data, options) | |
feed = feedgenerator.Atom1Feed( | |
title =u"News RSS Feed", | |
link=u"http://news.example.com", | |
description=u"News and Events" | |
) | |
for item in data['objects']: | |
feed.add_item(title=item['title'], link=item['url'], description=item['synopsis']) | |
return feed.writeString('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment