Django

Code

Changeset 5643

Show
Ignore:
Timestamp:
07/10/07 07:33:55 (1 year ago)
Author:
mtredinnick
Message:

Fixed #3760 -- Added the ability to manually set feed- and item-level id
elements in Atom feeds. This is fully backwards compatible. Based on a patch
from spark343@cs.ubc.ca.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/syndication/feeds.py

    r5629 r5643  
    8484            categories = self.__get_dynamic_attr('categories', obj), 
    8585            feed_copyright = self.__get_dynamic_attr('feed_copyright', obj), 
     86            feed_guid = self.__get_dynamic_attr('feed_guid', obj), 
    8687        ) 
    8788 
     
    115116                link = link, 
    116117                description = description_tmp.render(Context({'obj': item, 'site': current_site})), 
    117                 unique_id = link
     118                unique_id = self.__get_dynamic_attr('item_guid', item, link)
    118119                enclosure = enc, 
    119120                pubdate = self.__get_dynamic_attr('item_pubdate', item), 
  • django/trunk/django/utils/feedgenerator.py

    r5609 r5643  
    4242    def __init__(self, title, link, description, language=None, author_email=None, 
    4343            author_name=None, author_link=None, subtitle=None, categories=None, 
    44             feed_url=None, feed_copyright=None): 
     44            feed_url=None, feed_copyright=None, feed_guid=None): 
    4545        to_unicode = lambda s: force_unicode(s, strings_only=True) 
    4646        if categories: 
     
    5858            'feed_url': iri_to_uri(feed_url), 
    5959            'feed_copyright': to_unicode(feed_copyright), 
     60            'id': feed_guid or link, 
    6061        } 
    6162        self.items = [] 
     
    214215        if self.feed['feed_url'] is not None: 
    215216            handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']}) 
    216         handler.addQuickElement(u"id", self.feed['link']) 
     217        handler.addQuickElement(u"id", self.feed['id']) 
    217218        handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('ascii')) 
    218219        if self.feed['author_name'] is not None: 
  • django/trunk/docs/syndication_feeds.txt

    r5250 r5643  
    417417        link = '/foo/bar/' # Hard-coded link. 
    418418 
     419        # GUID -- One of the following three is optional. The framework looks 
     420        # for them in this order. This property is only used for Atom feeds 
     421        # (where it is the feed-level id element). If not provided, the feed 
     422        # link is used as the id. 
     423 
     424        def feed_guid(self, obj): 
     425            """ 
     426            Takes the object returned by get_object() and returns the globally 
     427            unique id for the feed as a normal Python string. 
     428            """ 
     429 
     430        def feed_guid(self): 
     431            """ 
     432            Returns the feed's globally unique id as a normal Python string. 
     433            """ 
     434 
     435        feed_guid = '/foo/bar/1234' # Hard-coded guid. 
     436 
    419437        # DESCRIPTION -- One of the following three is required. The framework 
    420438        # looks for them in this order. 
     
    555573            """ 
    556574            Returns the URL for every item in the feed. 
     575            """ 
     576 
     577        # ITEM_GUID -- The following method is optional. This property is 
     578        # only used for Atom feeds (it is the id element for an item in an 
     579        # Atom feed). If not provided, the item's link is used by default. 
     580 
     581        def item_guid(self, obj): 
     582            """ 
     583            Takes an item, as return by items(), and returns the item's id. 
    557584            """ 
    558585