Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 10 and Version 11 of FeedObject


Ignore:
Timestamp:
06/24/07 18:40:44 (12 years ago)
Author:
Chris Arndt
Comment:

migration notice

Legend:

Unmodified
Added
Removed
Modified
  • FeedObject

    v10 v11  
    1 Turbogears 0.9 will have support for rss/atom feeds. Here is a quicklook on how to use them. Any suggestions are welcome. 
    2  
    3 We assume here that we have blog that we want to add a feed to. 
    4  
    5 First we need to create the feed object. 
    6 Then we add a get_feed_data method to it. It is this that will be called to populate the feed everytime a user requests it. 
    7  
    81{{{ 
    9 #!python 
    10 from turbogears.feed import FeedController 
    11     class Feed(FeedController): 
    12         def get_feed_data(self): 
    13            
     2#!rst 
     3.. note:: This page has been migrated to http://docs.turbogears.org/1.0/FeedObject. 
    144}}} 
    15  
    16 now lets start adding some things to the feed. 
    17 We do this by returning a dict from get_feed_data with the elements we wish to have 
    18 {{{ 
    19 #!python 
    20         def get_feed_data(self): 
    21             entrys = [] 
    22  
    23             return dict( 
    24                 title="my fine blog", 
    25                 link="http://blog.foo.org", 
    26                 author = {"name":"John Doe","email":"john@foo.org"}, 
    27                 id = "http://blog.foo.org", 
    28                 subtitle="a blog about turbogears" 
    29                 entrys=entrys 
    30             ) 
    31 }}} 
    32  
    33 Now we need to get some elements for the posts in the feed so we extend our get_feed_data method for that. 
    34  
    35 Plese note that each foo dict is populated with the default for well form feeds but each entry object can be whatever you define, you can even populate it from diferent SQLObjects. So there is no need for you to know the definition of BlogEntry. 
    36 {{{ 
    37 #!python 
    38         def get_feed_data(self): 
    39  
    40             entrys = [] 
    41             # get all latest five blog entries in reversed order from SQLobject 
    42             for entry in list(BlogEntry.select()[:5].reversed()): 
    43                 foo = {} 
    44                 foo["updated"] = entry.updated 
    45                 foo["title"] = entry.title 
    46                 foo["published"] = entry.published  
    47                 foo["author"] = {"name":"elvelind grandin", "uri":"midvinter.org"} 
    48                 foo["summary"] = entry.post[:30] 
    49                 entrys.append(foo) 
    50  
    51             return dict( 
    52                 title="my fine blog", 
    53                 link="http://blog.foo.org", 
    54                 author = {"name":"John Doe","email":"john@foo.org"}, 
    55                 id = "http://blog.foo.org", 
    56                 subtitle="a blog about turbogears", 
    57                 entrys = entrys 
    58             ) 
    59 }}} 
    60 Now all we need is just to mount it in our controller 
    61  
    62 {{{ 
    63 #!python 
    64 Class Blog(controllers.Root): 
    65  
    66    feed = Feed() 
    67  
    68    .... 
    69  
    70 }}} 
    71  
    72 now we have serveral urls to use. 
    73 (assuming our blog is mounted as root) 
    74  * blog.foo.org/feed/atom1.0 
    75  * blog.foo.org/feed/atom0.3 
    76  * blog.foo.org/feed/rss2.0 
    77  * blog.foo.org/feed - which will redirect to the default feed (by standard atom1.0) 
    78  
    79  
    80 Note: 
    81 At this point the feed has no knowledge of which elements are necessary to create valid feed. 
    82 But this is something I expect to add in the near future.