Django

Code

Changeset 1227

Show
Ignore:
Timestamp:
11/13/05 22:59:20 (3 years ago)
Author:
adrian
Message:

Improved Atom feed-generating framework to output <link rel='self'>. Added a feed_url hook to feedgenerator for this purpose, and changed the syndication Feed and views to use it. Also updated docs.

Files:

Legend:

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

    r1194 r1227  
    1818    feed_type = feedgenerator.DefaultFeed 
    1919 
    20     def __init__(self, slug): 
     20    def __init__(self, slug, feed_url): 
    2121        self.slug = slug 
     22        self.feed_url = feed_url 
    2223 
    2324    def item_link(self, item): 
     
    5758            link = link, 
    5859            description = self.__get_dynamic_attr('description', obj), 
    59             language = LANGUAGE_CODE.decode() 
     60            language = LANGUAGE_CODE.decode(), 
     61            feed_url = add_domain(current_site, self.feed_url), 
    6062        ) 
    6163 
  • django/trunk/django/contrib/syndication/views.py

    r1201 r1227  
    1818 
    1919    try: 
    20         feedgen = f(slug).get_feed(param) 
     20        feedgen = f(slug, request.path).get_feed(param) 
    2121    except feeds.FeedDoesNotExist: 
    2222        raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug 
  • django/trunk/django/utils/feedgenerator.py

    r1226 r1227  
    4242    "Base class for all syndication feeds. Subclasses should provide write()" 
    4343    def __init__(self, title, link, description, language=None, author_email=None, 
    44             author_name=None, author_link=None, subtitle=None, categories=None): 
     44            author_name=None, author_link=None, subtitle=None, categories=None, 
     45            feed_url=None): 
    4546        self.feed = { 
    4647            'title': title, 
     
    5354            'subtitle': subtitle, 
    5455            'categories': categories or (), 
     56            'feed_url': feed_url, 
    5557        } 
    5658        self.items = [] 
     
    191193            handler.startElement(u"feed", {u"xmlns": self.ns}) 
    192194        handler.addQuickElement(u"title", self.feed['title']) 
    193         handler.addQuickElement(u"link", "", {u"href": self.feed['link']}) 
     195        handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']}) 
     196        if self.feed['feed_url'] is not None: 
     197            handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']}) 
    194198        handler.addQuickElement(u"id", self.feed['link']) 
    195199        handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('ascii')) 
  • django/trunk/docs/syndication_feeds.txt

    r1197 r1227  
    267267.. _LANGUAGE_CODE setting: http://www.djangoproject.com/documentation/settings/#language-code 
    268268 
     269URLs 
     270---- 
     271 
     272The ``link`` method/attribute can return either an absolute URL (e.g. 
     273``"/blog/"``) or a URL with the fully-qualified domain and protocol (e.g. 
     274``"http://www.example.com/blog/"``). If ``link`` doesn't return the domain, 
     275the syndication framework will insert the domain of the current site, according 
     276to your `SITE_ID setting`_. 
     277 
     278Atom feeds require a ``<link rel="self">`` that defines the feed's current 
     279location. The syndication framework populates this automatically, using the 
     280domain of the current site according to the SITE_ID setting. 
     281 
     282.. _SITE_ID setting: http://www.djangoproject.com/documentation/settings/#site-id 
     283 
    269284Publishing Atom and RSS feeds in tandem 
    270285--------------------------------------- 
     
    502517 
    503518``__init__(title, link, description, language=None, author_email=None,`` 
    504 ``author_name=None, author_link=None, subtitle=None, categories=None)`` 
     519``author_name=None, author_link=None, subtitle=None, categories=None,`` 
     520``feed_url=None)`` 
    505521 
    506522Initializes the feed with the given metadata, which applies to the entire feed