Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #8253: fixed xmlns regression for Atom feeds, and in the proces…

…s added a hook for adding attributes specifically on the root <rss> element (for RSS feeds only, of course). Patch by Justin Bronn.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8331 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d05c7253084ea73dfd734099455f3d8964d4cf25 1 parent ca020a5
@jacobian jacobian authored
View
7 django/utils/feedgenerator.py
@@ -178,13 +178,16 @@ class RssFeed(SyndicationFeed):
def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding)
handler.startDocument()
- handler.startElement(u"rss", {u"version": self._version})
+ handler.startElement(u"rss", self.rss_attributes())
handler.startElement(u"channel", self.root_attributes())
self.add_root_elements(handler)
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement(u"rss")
+ def rss_attributes(self):
+ return {u"version": self._version}
+
def write_items(self, handler):
for item in self.items:
handler.startElement(u'item', self.item_attributes(item))
@@ -266,7 +269,7 @@ def write(self, outfile, encoding):
self.write_items(handler)
handler.endElement(u"feed")
- def root_element_attributes(self):
+ def root_attributes(self):
if self.feed['language'] is not None:
return {u"xmlns": self.ns, u"xml:lang": self.feed['language']}
else:
View
17 tests/regressiontests/syndication/tests.py
@@ -20,9 +20,19 @@ def assertChildNodes(self, elem, expected):
def test_rss_feed(self):
response = self.client.get('/syndication/feeds/rss/')
doc = minidom.parseString(response.content)
- self.assertEqual(len(doc.getElementsByTagName('channel')), 1)
-
- chan = doc.getElementsByTagName('channel')[0]
+
+ # Making sure there's only 1 `rss` element and that the correct
+ # RSS version was specified.
+ feed_elem = doc.getElementsByTagName('rss')
+ self.assertEqual(len(feed_elem), 1)
+ feed = feed_elem[0]
+ self.assertEqual(feed.getAttribute('version'), '2.0')
+
+ # Making sure there's only one `channel` element w/in the
+ # `rss` element.
+ chan_elem = feed.getElementsByTagName('channel')
+ self.assertEqual(len(chan_elem), 1)
+ chan = chan_elem[0]
self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item'])
items = chan.getElementsByTagName('item')
@@ -36,6 +46,7 @@ def test_atom_feed(self):
feed = doc.firstChild
self.assertEqual(feed.nodeName, 'feed')
+ self.assertEqual(feed.getAttribute('xmlns'), 'http://www.w3.org/2005/Atom')
self.assertChildNodes(feed, ['title', 'link', 'id', 'updated', 'entry'])
entries = feed.getElementsByTagName('entry')
Please sign in to comment.
Something went wrong with that request. Please try again.