Code

Ticket #3502: feed_ttl.diff

File feed_ttl.diff, 4.4 KB (added by toke, 7 years ago)

Patch against [6188]

Line 
1Index: django/contrib/syndication/feeds.py
2===================================================================
3--- django/contrib/syndication/feeds.py (Revision 6220)
4+++ django/contrib/syndication/feeds.py (Arbeitskopie)
5@@ -89,6 +89,7 @@
6             categories = self.__get_dynamic_attr('categories', obj),
7             feed_copyright = self.__get_dynamic_attr('feed_copyright', obj),
8             feed_guid = self.__get_dynamic_attr('feed_guid', obj),
9+            ttl = self.__get_dynamic_attr('ttl', obj),
10         )
11 
12         try:
13Index: django/utils/feedgenerator.py
14===================================================================
15--- django/utils/feedgenerator.py       (Revision 6220)
16+++ django/utils/feedgenerator.py       (Arbeitskopie)
17@@ -41,7 +41,7 @@
18     "Base class for all syndication feeds. Subclasses should provide write()"
19     def __init__(self, title, link, description, language=None, author_email=None,
20             author_name=None, author_link=None, subtitle=None, categories=None,
21-            feed_url=None, feed_copyright=None, feed_guid=None):
22+            feed_url=None, feed_copyright=None, feed_guid=None, ttl=None):
23         to_unicode = lambda s: force_unicode(s, strings_only=True)
24         if categories:
25             categories = [force_unicode(c) for c in categories]
26@@ -58,12 +58,13 @@
27             'feed_url': iri_to_uri(feed_url),
28             'feed_copyright': to_unicode(feed_copyright),
29             'id': feed_guid or link,
30+            'ttl': ttl,
31         }
32         self.items = []
33 
34     def add_item(self, title, link, description, author_email=None,
35         author_name=None, author_link=None, pubdate=None, comments=None,
36-        unique_id=None, enclosure=None, categories=(), item_copyright=None):
37+        unique_id=None, enclosure=None, categories=(), item_copyright=None, ttl=None):
38         """
39         Adds an item to the feed. All args are expected to be Python Unicode
40         objects except pubdate, which is a datetime.datetime object, and
41@@ -85,6 +86,7 @@
42             'enclosure': enclosure,
43             'categories': categories or (),
44             'item_copyright': to_unicode(item_copyright),
45+            'ttl': ttl,
46         })
47 
48     def num_items(self):
49@@ -142,6 +144,8 @@
50         if self.feed['feed_copyright'] is not None:
51             handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
52         handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('ascii'))
53+        if self.feed['ttl'] is not None:
54+            handler.addQuickElement(u"ttl", self.feed['ttl'])
55         self.write_items(handler)
56         self.endChannelElement(handler)
57         handler.endElement(u"rss")
58@@ -186,6 +190,8 @@
59                 handler.addQuickElement(u"comments", item['comments'])
60             if item['unique_id'] is not None:
61                 handler.addQuickElement(u"guid", item['unique_id'])
62+            if item['ttl'] is not None:
63+                handler.addQuickElement(u"ttl", item['ttl'])
64 
65             # Enclosure.
66             if item['enclosure'] is not None:
67Index: AUTHORS
68===================================================================
69--- AUTHORS     (Revision 6220)
70+++ AUTHORS     (Arbeitskopie)
71@@ -163,6 +163,7 @@
72     Nagy Károly <charlie@rendszergazda.com>
73     Ben Dean Kawamura <ben.dean.kawamura@gmail.com>
74     Ian G. Kelly <ian.g.kelly@gmail.com>
75+    Thomas Kerpe <thomas@kerpe.net>
76     Ben Khoo <khoobks@westnet.com.au>
77     Garth Kidd <http://www.deadlybloodyserious.com/>
78     kilian <kilian.cavalotti@lip6.fr>
79Index: docs/syndication_feeds.txt
80===================================================================
81--- docs/syndication_feeds.txt  (Revision 6220)
82+++ docs/syndication_feeds.txt  (Arbeitskopie)
83@@ -547,6 +547,24 @@
84 
85         copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice.
86 
87+        # TTL -- One of the following three is optional. The
88+        # framework looks for them in this order.
89+
90+        def ttl(self, obj):
91+            """
92+            Takes the object returned by get_object() and returns the feed's
93+            TTL (Time to live) as a normal Python string.
94+            """
95+
96+        def ttl(self):
97+            """
98+            Returns the feed's ttl as a normal Python string.
99+            """
100+
101+        ttl = 600 # Hard-coded Time to live.
102+
103+
104+
105         # ITEMS -- One of the following three is required. The framework looks
106         # for them in this order.
107