Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 8a3cf46e6021e9e9b5640c3f79625564527aa165 1 parent 18e1f56
@malcolmt malcolmt authored
View
2  AUTHORS
@@ -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
1  django/contrib/syndication/feeds.py
@@ -89,6 +89,7 @@ def get_feed(self, url=None):
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
10 django/utils/feedgenerator.py
@@ -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 @@ def __init__(self, title, link, description, language=None, author_email=None,
'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 @@ def add_item(self, title, link, description, author_email=None,
'enclosure': enclosure,
'categories': categories or (),
'item_copyright': to_unicode(item_copyright),
+ 'ttl': ttl,
})
def num_items(self):
@@ -146,6 +148,8 @@ def write(self, outfile, encoding):
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 @@ def write_items(self, handler):
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
16 docs/syndication_feeds.txt
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.