Ticket #9800: support_is_permalink_attr_in_rss_guid.patch

File support_is_permalink_attr_in_rss_guid.patch, 3.3 KB (added by rtnpro, 2 years ago)

Support 'isPermalink' attribute in <guid> element for an item in RSS feed.

  • django/contrib/syndication/views.py

    diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
    index 996b7df..a80b9d1 100644
    a b class Feed(object): 
    184184                link = link,
    185185                description = description,
    186186                unique_id = self.__get_dynamic_attr('item_guid', item, link),
     187                unique_id_is_permalink = self.__get_dynamic_attr(
     188                    'item_guid_is_permalink', item),
    187189                enclosure = enc,
    188190                pubdate = pubdate,
    189191                author_name = author_name,
  • django/utils/feedgenerator.py

    diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
    index f9126a6..cdb4769 100644
    a b class SyndicationFeed(object): 
    113113
    114114    def add_item(self, title, link, description, author_email=None,
    115115        author_name=None, author_link=None, pubdate=None, comments=None,
    116         unique_id=None, enclosure=None, categories=(), item_copyright=None,
    117         ttl=None, **kwargs):
     116        unique_id=None, unique_id_is_permalink=None, enclosure=None,
     117        categories=(), item_copyright=None, ttl=None, **kwargs):
    118118        """
    119119        Adds an item to the feed. All args are expected to be Python Unicode
    120120        objects except pubdate, which is a datetime.datetime object, and
    class SyndicationFeed(object): 
    136136            'pubdate': pubdate,
    137137            'comments': to_unicode(comments),
    138138            'unique_id': to_unicode(unique_id),
     139            'unique_id_is_permalink': unique_id_is_permalink,
    139140            'enclosure': enclosure,
    140141            'categories': categories or (),
    141142            'item_copyright': to_unicode(item_copyright),
    class Rss201rev2Feed(RssFeed): 
    280281        if item['comments'] is not None:
    281282            handler.addQuickElement("comments", item['comments'])
    282283        if item['unique_id'] is not None:
    283             handler.addQuickElement("guid", item['unique_id'])
     284            guid_attrs = {}
     285            if isinstance(item.get('unique_id_is_permalink'), bool):
     286                guid_attrs['isPermalink'] = str(
     287                    item['unique_id_is_permalink']).lower()
     288            handler.addQuickElement("guid", item['unique_id'], guid_attrs)
    284289        if item['ttl'] is not None:
    285290            handler.addQuickElement("ttl", item['ttl'])
    286291
  • docs/ref/contrib/syndication.txt

    diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt
    index 2955d7d..1fbc718 100644
    a b This example illustrates all possible attributes and methods for a 
    624624            Takes an item, as return by items(), and returns the item's ID.
    625625            """
    626626
     627        # ITEM_GUID_IS_PERMALINK -- The following method is optional. If
     628        # provided, it sets the 'isPermalink' attribute of an item's
     629        # GUID element. This method is used only when 'item_guid' is
     630        # specified.
     631
     632        def item_guid_is_permalink(self, obj):
     633            """
     634            Takes an item, as returned by items(), and returns a boolean.
     635            """
     636
     637        item_guid_is_permalink = False  # Hard coded value
     638
    627639        # ITEM AUTHOR NAME -- One of the following three is optional. The
    628640        # framework looks for them in this order.
    629641
Back to Top