summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-02-10 08:36:39 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-02-10 08:36:39 +0000
commit937f3190baabb5c98398b391bcf8250bbb738da5 (patch)
tree5b7971b36837305a23ebe6c751e9ddff972d899d /django
parentfefcbbfe3719eaf0b493eabaab591c0b7bc35d9e (diff)
Fixed #2762 -- added copyright element support to RSS and Atom feeds. Patch
from Jonathan Buchanan. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4478 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/syndication/feeds.py2
-rw-r--r--django/utils/feedgenerator.py16
2 files changed, 15 insertions, 3 deletions
diff --git a/django/contrib/syndication/feeds.py b/django/contrib/syndication/feeds.py
index 119615a0b9..cdb4e8170f 100644
--- a/django/contrib/syndication/feeds.py
+++ b/django/contrib/syndication/feeds.py
@@ -78,6 +78,7 @@ class Feed(object):
author_link = self.__get_dynamic_attr('author_link', obj),
author_email = self.__get_dynamic_attr('author_email', obj),
categories = self.__get_dynamic_attr('categories', obj),
+ feed_copyright = self.__get_dynamic_attr('feed_copyright', obj),
)
try:
@@ -116,5 +117,6 @@ class Feed(object):
author_email = author_email,
author_link = author_link,
categories = self.__get_dynamic_attr('item_categories', item),
+ item_copyright = self.__get_dynamic_attr('item_copyright', item),
)
return feed
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index 2eb27a40b7..9397789d6a 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -40,7 +40,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_url=None, feed_copyright=None):
self.feed = {
'title': title,
'link': link,
@@ -52,12 +52,13 @@ class SyndicationFeed(object):
'subtitle': subtitle,
'categories': categories or (),
'feed_url': feed_url,
+ 'feed_copyright': feed_copyright,
}
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=()):
+ unique_id=None, enclosure=None, categories=(), item_copyright=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
@@ -75,6 +76,7 @@ class SyndicationFeed(object):
'unique_id': unique_id,
'enclosure': enclosure,
'categories': categories or (),
+ 'item_copyright': item_copyright,
})
def num_items(self):
@@ -128,6 +130,8 @@ class RssFeed(SyndicationFeed):
handler.addQuickElement(u"language", self.feed['language'])
for cat in self.feed['categories']:
handler.addQuickElement(u"category", cat)
+ if self.feed['feed_copyright'] is not None:
+ handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement(u"rss")
@@ -212,6 +216,8 @@ class Atom1Feed(SyndicationFeed):
handler.addQuickElement(u"subtitle", self.feed['subtitle'])
for cat in self.feed['categories']:
handler.addQuickElement(u"category", "", {u"term": cat})
+ if self.feed['feed_copyright'] is not None:
+ handler.addQuickElement(u"rights", self.feed['feed_copyright'])
self.write_items(handler)
handler.endElement(u"feed")
@@ -252,10 +258,14 @@ class Atom1Feed(SyndicationFeed):
u"length": item['enclosure'].length,
u"type": item['enclosure'].mime_type})
- # Categories:
+ # Categories.
for cat in item['categories']:
handler.addQuickElement(u"category", u"", {u"term": cat})
+ # Rights.
+ if item['item_copyright'] is not None:
+ handler.addQuickElement(u"rights", item['item_copyright'])
+
handler.endElement(u"entry")
# This isolates the decision of what the system default is, so calling code can