Ticket #8253: feed_root_attributes.diff
File feed_root_attributes.diff, 2.8 KB (added by , 16 years ago) |
---|
-
django/utils/feedgenerator.py
178 178 def write(self, outfile, encoding): 179 179 handler = SimplerXMLGenerator(outfile, encoding) 180 180 handler.startDocument() 181 handler.startElement(u"rss", {u"version": self._version})181 handler.startElement(u"rss", self.rss_attributes()) 182 182 handler.startElement(u"channel", self.root_attributes()) 183 183 self.add_root_elements(handler) 184 184 self.write_items(handler) 185 185 self.endChannelElement(handler) 186 186 handler.endElement(u"rss") 187 187 188 def rss_attributes(self): 189 return {u"version": self._version} 190 188 191 def write_items(self, handler): 189 192 for item in self.items: 190 193 handler.startElement(u'item', self.item_attributes(item)) … … 266 269 self.write_items(handler) 267 270 handler.endElement(u"feed") 268 271 269 def root_ element_attributes(self):272 def root_attributes(self): 270 273 if self.feed['language'] is not None: 271 274 return {u"xmlns": self.ns, u"xml:lang": self.feed['language']} 272 275 else: -
tests/regressiontests/syndication/tests.py
20 20 def test_rss_feed(self): 21 21 response = self.client.get('/syndication/feeds/rss/') 22 22 doc = minidom.parseString(response.content) 23 self.assertEqual(len(doc.getElementsByTagName('channel')), 1) 24 25 chan = doc.getElementsByTagName('channel')[0] 23 24 # Making sure there's only 1 `rss` element and that the correct 25 # RSS version was specified. 26 feed_elem = doc.getElementsByTagName('rss') 27 self.assertEqual(len(feed_elem), 1) 28 feed = feed_elem[0] 29 self.assertEqual(feed.getAttribute('version'), '2.0') 30 31 # Making sure there's only one `channel` element w/in the 32 # `rss` element. 33 chan_elem = feed.getElementsByTagName('channel') 34 self.assertEqual(len(chan_elem), 1) 35 chan = chan_elem[0] 26 36 self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item']) 27 37 28 38 items = chan.getElementsByTagName('item') … … 36 46 37 47 feed = doc.firstChild 38 48 self.assertEqual(feed.nodeName, 'feed') 49 self.assertEqual(feed.getAttribute('xmlns'), 'http://www.w3.org/2005/Atom') 39 50 self.assertChildNodes(feed, ['title', 'link', 'id', 'updated', 'entry']) 40 51 41 52 entries = feed.getElementsByTagName('entry')