summaryrefslogtreecommitdiff
path: root/django/utils/feedgenerator.py
diff options
context:
space:
mode:
authorChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
committerChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
commitae22b6d403dcf25098c77f0dfcf59ae58b186461 (patch)
treec37fc631e99a7e4d909d6b6d236f495003731ea7 /django/utils/feedgenerator.py
parent0cf7bc439129c66df8d64601e885f83b256b4f25 (diff)
per-object-permissions: Merged to trunk [5486] NOTE: Not fully tested, will be working on this over the next few weeks.
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@5488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/feedgenerator.py')
-rw-r--r--django/utils/feedgenerator.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index 2eb27a40b7..2c82e9a37a 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,9 @@ 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'])
+ handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('ascii'))
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement(u"rss")
@@ -163,6 +168,8 @@ class Rss201rev2Feed(RssFeed):
(item['author_email'], item['author_name']))
elif item["author_email"]:
handler.addQuickElement(u"author", item["author_email"])
+ elif item["author_name"]:
+ handler.addQuickElement(u"dc:creator", item["author_name"], {"xmlns:dc": u"http://purl.org/dc/elements/1.1/"})
if item['pubdate'] is not None:
handler.addQuickElement(u"pubDate", rfc2822_date(item['pubdate']).decode('ascii'))
@@ -212,6 +219,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 +261,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