Fixed #3502 -- Added TTL support for RSS (not Atom) feeds. Patch from

jason.sidabras@gmail.com and Thomas Kerpe.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6570 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-10-20 14:54:38 +00:00
parent 18e1f56a41
commit 8a3cf46e60
4 changed files with 27 additions and 2 deletions

View File

@ -170,6 +170,7 @@ answer newbie questions, and generally made Django that much better:
Nagy Károly <charlie@rendszergazda.com>
Ben Dean Kawamura <ben.dean.kawamura@gmail.com>
Ian G. Kelly <ian.g.kelly@gmail.com>
Thomas Kerpe <thomas@kerpe.net>
Ben Khoo <khoobks@westnet.com.au>
Garth Kidd <http://www.deadlybloodyserious.com/>
kilian <kilian.cavalotti@lip6.fr>
@ -273,6 +274,7 @@ answer newbie questions, and generally made Django that much better:
serbaut@gmail.com
John Shaffer <jshaffer2112@gmail.com>
Pete Shinners <pete@shinners.org>
jason.sidabras@gmail.com
Jozko Skrablin <jozko.skrablin@gmail.com>
SmileyChris <smileychris@gmail.com>
smurf@smurf.noris.de

View File

@ -89,6 +89,7 @@ class Feed(object):
categories = self.__get_dynamic_attr('categories', obj),
feed_copyright = self.__get_dynamic_attr('feed_copyright', obj),
feed_guid = self.__get_dynamic_attr('feed_guid', obj),
ttl = self.__get_dynamic_attr('ttl', obj),
)
try:

View File

@ -45,7 +45,7 @@ class SyndicationFeed(object):
"Base class for all syndication feeds. Subclasses should provide write()"
def __init__(self, title, link, description, language=None, author_email=None,
author_name=None, author_link=None, subtitle=None, categories=None,
feed_url=None, feed_copyright=None, feed_guid=None):
feed_url=None, feed_copyright=None, feed_guid=None, ttl=None):
to_unicode = lambda s: force_unicode(s, strings_only=True)
if categories:
categories = [force_unicode(c) for c in categories]
@ -62,12 +62,13 @@ class SyndicationFeed(object):
'feed_url': iri_to_uri(feed_url),
'feed_copyright': to_unicode(feed_copyright),
'id': feed_guid or link,
'ttl': ttl,
}
self.items = []
def add_item(self, title, link, description, author_email=None,
author_name=None, author_link=None, pubdate=None, comments=None,
unique_id=None, enclosure=None, categories=(), item_copyright=None):
unique_id=None, enclosure=None, categories=(), item_copyright=None, ttl=None):
"""
Adds an item to the feed. All args are expected to be Python Unicode
objects except pubdate, which is a datetime.datetime object, and
@ -89,6 +90,7 @@ class SyndicationFeed(object):
'enclosure': enclosure,
'categories': categories or (),
'item_copyright': to_unicode(item_copyright),
'ttl': ttl,
})
def num_items(self):
@ -146,6 +148,8 @@ class RssFeed(SyndicationFeed):
if self.feed['feed_copyright'] is not None:
handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('ascii'))
if self.feed['ttl'] is not None:
handler.addQuickElement(u"ttl", self.feed['ttl'])
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement(u"rss")
@ -190,6 +194,8 @@ class Rss201rev2Feed(RssFeed):
handler.addQuickElement(u"comments", item['comments'])
if item['unique_id'] is not None:
handler.addQuickElement(u"guid", item['unique_id'])
if item['ttl'] is not None:
handler.addQuickElement(u"ttl", item['ttl'])
# Enclosure.
if item['enclosure'] is not None:

View File

@ -547,6 +547,22 @@ This example illustrates all possible attributes and methods for a ``Feed`` clas
copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice.
# TTL -- One of the following three is optional. The framework looks
# for them in this order. Ignored for Atom feeds.
def ttl(self, obj):
"""
Takes the object returned by get_object() and returns the feed's
TTL (Time to live) as a normal Python string.
"""
def ttl(self):
"""
Returns the feed's ttl as a normal Python string.
"""
ttl = 600 # Hard-coded Time to live.
# ITEMS -- One of the following three is required. The framework looks
# for them in this order.