Skip to content

Instantly share code, notes, and snippets.

@dstegelman
Created June 19, 2014 02:06
Show Gist options
  • Save dstegelman/b3f64f446591bef7912a to your computer and use it in GitHub Desktop.
Save dstegelman/b3f64f446591bef7912a to your computer and use it in GitHub Desktop.
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