Ticket #12978: 12978.2.diff

File 12978.2.diff, 5.3 KB (added by Tim Graham, 11 years ago)
  • django/contrib/syndication/views.py

    diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
    index cec204d..4d34e84 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 de32b9f..504ec89 100644
    a b class SyndicationFeed(object):  
    8686    "Base class for all syndication feeds. Subclasses should provide write()"
    8787    def __init__(self, title, link, description, language=None, author_email=None,
    8888            author_name=None, author_link=None, subtitle=None, categories=None,
    89             feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
     89            feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, stylesheets=None, **kwargs):
    9090        to_unicode = lambda s: force_text(s, strings_only=True)
    9191        if categories:
    9292            categories = [force_text(c) for c in categories]
    9393        if ttl is not None:
    9494            # Force ints to unicode
    9595            ttl = force_text(ttl)
     96        if stylesheets:
     97            stylesheets = [iri_to_uri(s) for s in stylesheets]
    9698        self.feed = {
    9799            'title': to_unicode(title),
    98100            'link': iri_to_uri(link),
    class SyndicationFeed(object):  
    107109            'feed_copyright': to_unicode(feed_copyright),
    108110            'id': feed_guid or link,
    109111            'ttl': ttl,
     112            'stylesheets': stylesheets or (),
    110113        }
    111114        self.feed.update(kwargs)
    112115        self.items = []
    class RssFeed(SyndicationFeed):  
    219222    def write(self, outfile, encoding):
    220223        handler = SimplerXMLGenerator(outfile, encoding)
    221224        handler.startDocument()
     225        for s in self.feed['stylesheets']:
     226            # http://www.w3.org/TR/xml-stylesheet/
     227            handler.processingInstruction('xml-stylesheet', 'type="text/css" href="%s"' % s)
    222228        handler.startElement("rss", self.rss_attributes())
    223229        handler.startElement("channel", self.root_attributes())
    224230        self.add_root_elements(handler)
  • docs/ref/contrib/syndication.txt

    diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt
    index 9a0fb58..74d3fd5 100644
    a b Atom feeds require a ``<link rel="self">`` that defines the feed's current  
    327327location. The syndication framework populates this automatically, using the
    328328domain of the current site according to the :setting:`SITE_ID` setting.
    329329
     330Stylesheets
     331-----------
     332
     333.. versionadded:: 1.7
     334
     335RSS feeds support the inclusion of stylesheets via the ``stylesheets``
     336attribute, as a sequence of stylesheets to be added to the feed.
     337
    330338Publishing Atom and RSS feeds in tandem
    331339---------------------------------------
    332340
    This example illustrates all possible attributes and methods for a  
    591599
    592600        ttl = 600 # Hard-coded Time To Live.
    593601
     602        stylesheets = ('http://www.example.com/example.css',) # Hard-coded stylesheets to be added to feed
     603
    594604        # ITEMS -- One of the following three is required. The framework looks
    595605        # for them in this order.
    596606
    They share this interface:  
    918928    * ``feed_copyright``
    919929    * ``feed_guid``
    920930    * ``ttl``
     931    * ``stylesheets``
    921932
    922933    Any extra keyword arguments you pass to ``__init__`` will be stored in
    923934    ``self.feed`` for use with `custom feed generators`_.
    924935
    925     All parameters should be Unicode objects, except ``categories``, which
    926     should be a sequence of Unicode objects.
     936    All parameters should be Unicode objects, except ``categories`` and
     937    ``stylesheets``, which should be sequences of Unicode objects.
    927938
    928939:meth:`.SyndicationFeed.add_item`
    929940    Add an item to the feed with the given parameters.
  • tests/syndication/feeds.py

    diff --git a/tests/syndication/feeds.py b/tests/syndication/feeds.py
    index f8ffb4b..08b8aaf 100644
    a b class TestRss2Feed(views.Feed):  
    2525    categories = ('python', 'django')
    2626    feed_copyright = 'Copyright (c) 2007, Sally Smith'
    2727    ttl = 600
     28    stylesheets = ('http://www.example.com/example.css',)
    2829
    2930    def items(self):
    3031        return Entry.objects.all()
  • tests/syndication/tests.py

    diff --git a/tests/syndication/tests.py b/tests/syndication/tests.py
    index 8bc6b04..39b927e 100644
    a b class SyndicationFeedTest(FeedTestCase):  
    5151        feed = feed_elem[0]
    5252        self.assertEqual(feed.getAttribute('version'), '2.0')
    5353
     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
    5458        # Making sure there's only one `channel` element w/in the
    5559        # `rss` element.
    5660        chan_elem = feed.getElementsByTagName('channel')
Back to Top