summaryrefslogtreecommitdiff
path: root/django/utils/feedgenerator.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-01-28 13:46:18 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-01-28 13:46:18 +0000
commitc4c27d8a04c9125cfbc5c3611557d8e5d3845b0d (patch)
tree8aa6ee0d5b19ff096dc597e884dfa402d6ac8829 /django/utils/feedgenerator.py
parent3f68d255e24b5696537572ff351a8ad9f91d1b9d (diff)
Fixed #6188, #6304, #6618, #6969, #8758, #8989, #10334, #11069, #11973 and #12403 -- Modified the syndication framework to use class-based views. Thanks to Ben Firshman for his work on this patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12338 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/feedgenerator.py')
-rw-r--r--django/utils/feedgenerator.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index c9445f932f..06008d36e8 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -19,8 +19,8 @@ For definitions of the different versions of RSS, see:
http://diveintomark.org/archives/2004/02/04/incompatible-rss
"""
-import re
import datetime
+import urlparse
from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import force_unicode, iri_to_uri
@@ -46,12 +46,16 @@ def rfc3339_date(date):
return date.strftime('%Y-%m-%dT%H:%M:%SZ')
def get_tag_uri(url, date):
- "Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id"
- tag = re.sub('^http://', '', url)
+ """
+ Creates a TagURI.
+
+ See http://diveintomark.org/archives/2004/05/28/howto-atom-id
+ """
+ url_split = urlparse.urlparse(url)
+ d = ''
if date is not None:
- tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1)
- tag = re.sub('#', '/', tag)
- return u'tag:' + tag
+ d = ',%s' % date.strftime('%Y-%m-%d')
+ return u'tag:%s%s:%s/%s' % (url_split.hostname, d, url_split.path, url_split.fragment)
class SyndicationFeed(object):
"Base class for all syndication feeds. Subclasses should provide write()"
@@ -61,6 +65,9 @@ class SyndicationFeed(object):
to_unicode = lambda s: force_unicode(s, strings_only=True)
if categories:
categories = [force_unicode(c) for c in categories]
+ if ttl is not None:
+ # Force ints to unicode
+ ttl = force_unicode(ttl)
self.feed = {
'title': to_unicode(title),
'link': iri_to_uri(link),
@@ -91,6 +98,9 @@ class SyndicationFeed(object):
to_unicode = lambda s: force_unicode(s, strings_only=True)
if categories:
categories = [to_unicode(c) for c in categories]
+ if ttl is not None:
+ # Force ints to unicode
+ ttl = force_unicode(ttl)
item = {
'title': to_unicode(title),
'link': iri_to_uri(link),
@@ -186,7 +196,8 @@ class RssFeed(SyndicationFeed):
handler.endElement(u"rss")
def rss_attributes(self):
- return {u"version": self._version}
+ return {u"version": self._version,
+ u"xmlns:atom": u"http://www.w3.org/2005/Atom"}
def write_items(self, handler):
for item in self.items:
@@ -198,6 +209,7 @@ class RssFeed(SyndicationFeed):
handler.addQuickElement(u"title", self.feed['title'])
handler.addQuickElement(u"link", self.feed['link'])
handler.addQuickElement(u"description", self.feed['description'])
+ handler.addQuickElement(u"atom:link", None, {u"rel": u"self", u"href": self.feed['feed_url']})
if self.feed['language'] is not None:
handler.addQuickElement(u"language", self.feed['language'])
for cat in self.feed['categories']:
@@ -235,7 +247,7 @@ class Rss201rev2Feed(RssFeed):
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/"})
+ handler.addQuickElement(u"dc:creator", item["author_name"], {u"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('utf-8'))