Ticket #12978: 12978.diff
File 12978.diff, 5.3 KB (added by , 14 years ago) |
---|
-
django/utils/feedgenerator.py
### Eclipse Workspace Patch 1.0 #P django-trunk
71 71 "Base class for all syndication feeds. Subclasses should provide write()" 72 72 def __init__(self, title, link, description, language=None, author_email=None, 73 73 author_name=None, author_link=None, subtitle=None, categories=None, 74 feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):74 feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, stylesheets=None, **kwargs): 75 75 to_unicode = lambda s: force_unicode(s, strings_only=True) 76 76 if categories: 77 77 categories = [force_unicode(c) for c in categories] 78 78 if ttl is not None: 79 79 # Force ints to unicode 80 80 ttl = force_unicode(ttl) 81 if stylesheets: 82 stylesheets = [iri_to_uri(s) for s in stylesheets] 81 83 self.feed = { 82 84 'title': to_unicode(title), 83 85 'link': iri_to_uri(link), … … 92 94 'feed_copyright': to_unicode(feed_copyright), 93 95 'id': feed_guid or link, 94 96 'ttl': ttl, 97 'stylesheets': stylesheets or (), 95 98 } 96 99 self.feed.update(kwargs) 97 100 self.items = [] … … 198 201 def write(self, outfile, encoding): 199 202 handler = SimplerXMLGenerator(outfile, encoding) 200 203 handler.startDocument() 204 for s in self.feed['stylesheets']: 205 handler.processingInstruction('xml-stylesheet', 'type="text/css" href="%s"' % s) # http://www.w3.org/TR/xml-stylesheet/ 201 206 handler.startElement(u"rss", self.rss_attributes()) 202 207 handler.startElement(u"channel", self.root_attributes()) 203 208 self.add_root_elements(handler) -
docs/ref/contrib/syndication.txt
286 286 location. The syndication framework populates this automatically, using the 287 287 domain of the current site according to the :setting:`SITE_ID` setting. 288 288 289 Stylesheets 290 ----------- 291 292 RSS feeds support the inclusion of stylesheets via the :attr:`stylesheets` 293 attribute, as a sequence of stylesheets to be added to the feed. 294 289 295 Publishing Atom and RSS feeds in tandem 290 296 --------------------------------------- 291 297 … … 532 538 """ 533 539 534 540 ttl = 600 # Hard-coded Time To Live. 541 542 stylesheets = ('http://www.example.com/example.css',) # Hard-coded stylesheets to be added to feed 535 543 536 544 # ITEMS -- One of the following three is required. The framework looks 537 545 # for them in this order. … … 820 828 * ``feed_copyright`` 821 829 * ``feed_guid`` 822 830 * ``ttl`` 831 * ``stylesheets`` 823 832 824 833 Any extra keyword arguments you pass to ``__init__`` will be stored in 825 834 ``self.feed`` for use with `custom feed generators`_. 826 835 827 All parameters should be Unicode objects, except ``categories`` , which836 All parameters should be Unicode objects, except ``categories`` and ``stylesheets``, which 828 837 should be a sequence of Unicode objects. 829 838 830 839 .. method:: SyndicationFeed.add_item(**kwargs) -
tests/regressiontests/syndication/tests.py
50 50 self.assertEqual(len(feed_elem), 1) 51 51 feed = feed_elem[0] 52 52 self.assertEqual(feed.getAttribute('version'), '2.0') 53 53 54 # Verify document has a stylesheet element (processing instruction <?xml-stylesheet ... ?>) 55 self.assertEqual(doc.firstChild.target, 'xml-stylesheet') 56 self.assertEqual(doc.firstChild.data, 'type="text/css" href="http://www.example.com/example.css"') 57 54 58 # Making sure there's only one `channel` element w/in the 55 59 # `rss` element. 56 60 chan_elem = feed.getElementsByTagName('channel') -
django/contrib/syndication/views.py
114 114 feed_copyright = self.__get_dynamic_attr('feed_copyright', obj), 115 115 feed_guid = self.__get_dynamic_attr('feed_guid', obj), 116 116 ttl = self.__get_dynamic_attr('ttl', obj), 117 stylesheets = self.__get_dynamic_attr('stylesheets', obj), 117 118 **self.feed_extra_kwargs(obj) 118 119 ) 119 120 -
tests/regressiontests/syndication/feeds.py
22 22 categories = ('python', 'django') 23 23 feed_copyright = 'Copyright (c) 2007, Sally Smith' 24 24 ttl = 600 25 25 stylesheets = ('http://www.example.com/example.css',) 26 26 27 def items(self): 27 28 return Entry.objects.all() 28 29