mirror of https://github.com/django/django.git
Fixed #8253: fixed xmlns regression for Atom feeds, and in the process 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
This commit is contained in:
parent
ca020a5edd
commit
d05c725308
|
@ -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 @@ class Atom1Feed(SyndicationFeed):
|
|||
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:
|
||||
|
|
|
@ -20,9 +20,19 @@ class SyndicationFeedTest(TestCase):
|
|||
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 @@ class SyndicationFeedTest(TestCase):
|
|||
|
||||
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')
|
||||
|
|
Loading…
Reference in New Issue