Ticket #12978: 12978.3.diff

File 12978.3.diff, 5.4 KB (added by Tim Graham, 10 years ago)
  • django/contrib/syndication/views.py

    diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
    index e4ff6e6..cb453df 100644
    a b class Feed(object):  
    138138            feed_copyright=self.__get_dynamic_attr('feed_copyright', obj),
    139139            feed_guid=self.__get_dynamic_attr('feed_guid', obj),
    140140            ttl=self.__get_dynamic_attr('ttl', obj),
     141            stylesheets = self.__get_dynamic_attr('stylesheets', obj),
    141142            **self.feed_extra_kwargs(obj)
    142143        )
    143144
  • django/utils/feedgenerator.py

    diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
    index 52c0ecc..ac94d37 100644
    a b class SyndicationFeed(object):  
    8787    "Base class for all syndication feeds. Subclasses should provide write()"
    8888    def __init__(self, title, link, description, language=None, author_email=None,
    8989            author_name=None, author_link=None, subtitle=None, categories=None,
    90             feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
     90            feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, stylesheets=None, **kwargs):
    9191        to_unicode = lambda s: force_text(s, strings_only=True)
    9292        if categories:
    9393            categories = [force_text(c) for c in categories]
    9494        if ttl is not None:
    9595            # Force ints to unicode
    9696            ttl = force_text(ttl)
     97        if stylesheets:
     98            stylesheets = [iri_to_uri(s) for s in stylesheets]
    9799        self.feed = {
    98100            'title': to_unicode(title),
    99101            'link': iri_to_uri(link),
    class SyndicationFeed(object):  
    108110            'feed_copyright': to_unicode(feed_copyright),
    109111            'id': feed_guid or link,
    110112            'ttl': ttl,
     113            'stylesheets': stylesheets or (),
    111114        }
    112115        self.feed.update(kwargs)
    113116        self.items = []
    class RssFeed(SyndicationFeed):  
    223226    def write(self, outfile, encoding):
    224227        handler = SimplerXMLGenerator(outfile, encoding)
    225228        handler.startDocument()
     229        for s in self.feed['stylesheets']:
     230            # http://www.w3.org/TR/xml-stylesheet/
     231            handler.processingInstruction('xml-stylesheet', 'type="text/css" href="%s"' % s)
    226232        handler.startElement("rss", self.rss_attributes())
    227233        handler.startElement("channel", self.root_attributes())
    228234        self.add_root_elements(handler)
    class Atom1Feed(SyndicationFeed):  
    322328    def write(self, outfile, encoding):
    323329        handler = SimplerXMLGenerator(outfile, encoding)
    324330        handler.startDocument()
     331        for s in self.feed['stylesheets']:
     332            # http://www.w3.org/TR/xml-stylesheet/
     333            handler.processingInstruction('xml-stylesheet', 'type="text/css" href="%s"' % s)
    325334        handler.startElement('feed', self.root_attributes())
    326335        self.add_root_elements(handler)
    327336        self.write_items(handler)
  • docs/ref/contrib/syndication.txt

    diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt
    index 7e31eb0..9a213b6 100644
    a b Atom feeds require a ``<link rel="self">`` that defines the feed's current  
    323323location. The syndication framework populates this automatically, using the
    324324domain of the current site according to the :setting:`SITE_ID` setting.
    325325
     326Stylesheets
     327-----------
     328
     329.. versionadded:: 1.8
     330
     331RSS and Atom feeds support the inclusion of stylesheets via the ``stylesheets``
     332attribute, as a sequence of stylesheets to be added to the feed.
     333
    326334Publishing Atom and RSS feeds in tandem
    327335---------------------------------------
    328336
    This example illustrates all possible attributes and methods for a  
    587595
    588596        ttl = 600 # Hard-coded Time To Live.
    589597
     598        stylesheets = ('http://www.example.com/example.css',) # Hard-coded stylesheets to be added to feed
     599
    590600        # ITEMS -- One of the following three is required. The framework looks
    591601        # for them in this order.
    592602
    They share this interface:  
    914924    * ``feed_copyright``
    915925    * ``feed_guid``
    916926    * ``ttl``
     927    * ``stylesheets``
    917928
    918929    Any extra keyword arguments you pass to ``__init__`` will be stored in
    919930    ``self.feed`` for use with `custom feed generators`_.
    920931
    921     All parameters should be Unicode objects, except ``categories``, which
    922     should be a sequence of Unicode objects.
     932    All parameters should be Unicode objects, except ``categories`` and
     933    ``stylesheets``, which should be sequences of Unicode objects.
    923934
    924935:meth:`.SyndicationFeed.add_item`
    925936    Add an item to the feed with the given parameters.
  • tests/syndication_tests/tests.py

    diff --git a/tests/syndication_tests/tests.py b/tests/syndication_tests/tests.py
    index 8da3d5e..33952ea 100644
    a b class SyndicationFeedTest(FeedTestCase):  
    7070        feed = feed_elem[0]
    7171        self.assertEqual(feed.getAttribute('version'), '2.0')
    7272
     73        # Verify document has a stylesheet element (processing instruction <?xml-stylesheet ... ?>)
     74        self.assertEqual(doc.firstChild.target, 'xml-stylesheet')
     75        self.assertEqual(doc.firstChild.data, 'type="text/css" href="http://www.example.com/example.css"')
     76
    7377        # Making sure there's only one `channel` element w/in the
    7478        # `rss` element.
    7579        chan_elem = feed.getElementsByTagName('channel')
Back to Top