summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-07-10 12:33:55 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-07-10 12:33:55 +0000
commit86640f33c1f290a64452ce700e6f3da1ba618bdf (patch)
treed4c61b58f064729d74631acabaaa6db25897a30f /django
parent87d8976faee7b07a30ce1bd844b2b6178c3a3328 (diff)
Fixed #3760 -- Added the ability to manually set feed- and item-level id
elements in Atom feeds. This is fully backwards compatible. Based on a patch from spark343@cs.ubc.ca. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/syndication/feeds.py3
-rw-r--r--django/utils/feedgenerator.py5
2 files changed, 5 insertions, 3 deletions
diff --git a/django/contrib/syndication/feeds.py b/django/contrib/syndication/feeds.py
index b1d0cf02c7..547afb17f3 100644
--- a/django/contrib/syndication/feeds.py
+++ b/django/contrib/syndication/feeds.py
@@ -83,6 +83,7 @@ class Feed(object):
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),
+ feed_guid = self.__get_dynamic_attr('feed_guid', obj),
)
try:
@@ -114,7 +115,7 @@ class Feed(object):
title = title_tmp.render(Context({'obj': item, 'site': current_site})),
link = link,
description = description_tmp.render(Context({'obj': item, 'site': current_site})),
- unique_id = link,
+ unique_id = self.__get_dynamic_attr('item_guid', item, link),
enclosure = enc,
pubdate = self.__get_dynamic_attr('item_pubdate', item),
author_name = author_name,
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index 064ec19120..6b6dedfbe9 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -41,7 +41,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_url=None, feed_copyright=None, feed_guid=None):
to_unicode = lambda s: force_unicode(s, strings_only=True)
if categories:
categories = [force_unicode(c) for c in categories]
@@ -57,6 +57,7 @@ class SyndicationFeed(object):
'categories': categories or (),
'feed_url': iri_to_uri(feed_url),
'feed_copyright': to_unicode(feed_copyright),
+ 'id': feed_guid or link,
}
self.items = []
@@ -213,7 +214,7 @@ class Atom1Feed(SyndicationFeed):
handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']})
if self.feed['feed_url'] is not None:
handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']})
- handler.addQuickElement(u"id", self.feed['link'])
+ handler.addQuickElement(u"id", self.feed['id'])
handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('ascii'))
if self.feed['author_name'] is not None:
handler.startElement(u"author", {})