Package turbofeeds :: Module controllers :: Class FeedController
[hide private]

Class FeedController

source code

                       object --+    
                                |    
turbogears.controllers.Controller --+
                                    |
                                   FeedController

Controller for generating feeds in multiple formats.

Must be subclassed and a get_feed_data method provided that returns a dict with the feed info (see constructor doc strings) and an entries member, which should be a list filled with dicts each representing a feed entry (see docstring for the default implementation).

Instance Methods [hide private]
 
__init__(self, default='atom1.0', base_url='/feed', **feed_params)
Constructor - Should be called with super() if overwritten.
source code
 
index(self, *args, **kwargs)
Redirects to the default feed format rendering method.
source code
 
atom0_3(self, *args, **kwargs)
Renders Atom 0.3 XML feed.
source code
 
atom1_0(self, *args, **kwargs)
Renders Atom 1.0 XML feed.
source code
 
rss2_0(self, *args, **kwargs)
Renders RSS 2.0 XML feed.
source code
 
mrss1_1_1(self, *args, **kwargs)
Renders Media RSS 1.1.1 (extended from RSS 2.0) XML feed.
source code
 
date_to_3339(self, date)
Converts datatime object to RFC 3339 string representation.
source code
 
date_to_822(self, date)
Converts datatime object to RFC 822 string representation.
source code
 
format_dates(self, feed, format)
Converts datetime objects in the feed data into given format.
source code
 
get_feed_data(self, *args, **kwargs)
Returns dict with feed info and a list of feed entries.
source code
 
get_feed_url(self, version='atom1_0', *args, **kwargs)
Returns absolute URL (including server name) for the feed.
source code
 
init_feed(self, format)
Initializes feed data with the kwargs given to the constructor.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  formats = ['atom1.0', 'atom0.3', 'rss2.0', 'mrss1.1.1']
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, default='atom1.0', base_url='/feed', **feed_params)
(Constructor)

source code 

Constructor - Should be called with super() if overwritten.

The default arguments sets the default feed format when the feed base URL is requested. Currently supported values are atom1_0 (the default), atom0_3, rss2_0 and mrss1_1_1.

The base_url sets the URL where the feed controller is mounted to the CherryPy object tree. The default is '/feed'. This is used to construct the full feed URL for the link element in the feed, if it is not overwritten by the link keyword argument.

Any extra keyword arguments will be assigned to the feed_params attribute and added to the feed data everytime a feed is requested. This can be used to set the feed info in the direct child elements of the feed (Atom) resp. channel (RSS) root element of the feed. Possible names include:

  • author (dict with name, email and uri members)
  • categories (list of strings, used by Atom 1.0 / RSS only)
  • generator (string)
  • updated (datetime)
  • icon (URL, used by Atom 1.0 format only)
  • id (string/URL, used by Atom formats only)
  • logo (URL, used by Atom 1.0 / RSS format only)
  • lang (string, used by RSS format only)
  • link (URL)
  • rights (string)
  • subtitle (string)
  • stylesheet (URL or dict with members href and type or a callable returning either, used to place an appropriate xml-stylesheet processing instruction at the top of the feed XML. The stylesheet function will receive the format of the feed as the first argument and all extra keyword arguments to this constructor as keword arguments as well.)
  • title (string)

For up-to-date information about supported elements and values, please refer to the templates for the different feed formats in the templates sub-package.

Overrides: object.__init__

index(self, *args, **kwargs)

source code 
Redirects to the default feed format rendering method.
Decorators:
  • @tg.expose()

atom0_3(self, *args, **kwargs)

source code 
Renders Atom 0.3 XML feed.
Decorators:
  • @tg.expose(template= "turbofeeds.templates.atom0_3", format= "xml", content_type= "application/atom+xml")

atom1_0(self, *args, **kwargs)

source code 
Renders Atom 1.0 XML feed.
Decorators:
  • @tg.expose(template= "turbofeeds.templates.atom1_0", format= "xml", content_type= "application/atom+xml")

rss2_0(self, *args, **kwargs)

source code 
Renders RSS 2.0 XML feed.
Decorators:
  • @tg.expose(template= "turbofeeds.templates.rss2_0", format= "xml", content_type= "application/rss+xml")

mrss1_1_1(self, *args, **kwargs)

source code 
Renders Media RSS 1.1.1 (extended from RSS 2.0) XML feed.
Decorators:
  • @tg.expose(template= "turbofeeds.templates.mrss1_1_1", format= "xml", content_type= "application/rss+xml")

get_feed_data(self, *args, **kwargs)

source code 

Returns dict with feed info and a list of feed entries.

This method must be overwritten by a subclass.

It should return a dictionary with members for the feed info (see the constructor doc string) and a member entries, which is a list with dict items for each feed entry. Supported members in each dict include:

  • author (dict with name, email and uri members)
  • categories (list of strings, used by Atom 1.0 / RSS only)
  • content (string or dict with type and value members, Atom formats only)
  • updated (datetime, Atom only)
  • id (string/URL, Atom only)
  • link (URL)
  • published (datetime)
  • rights (string, Atom 1.0 only)
  • summary (string)
  • title (string)

For up-to-date information about supported elements and values, please refer to the templates for the different feed formats in the templates sub-package.