This class simplies the Feed class of django. The differences are:
1. Don't need define title and description template file
2. default feed generator class is Atom1Feed
3. According feed_url, EasyFeed can auto get the domain field, and you can also specify the domain parameter.(feed_url should be a full domain path, so you can use [Get the full request path](http://www.djangosnippets.org/snippets/41/) to get the full path of the feed url.)
4. There is a helper function render_feed() to return a response value.
example
---------
Feed class:
class BookCommentsFeed(EasyFeed):
def __init__(self, feed_url, book_id):
super(BookCommentsFeed, self).__init__(feed_url)
self.book_id = book_id
self.book = Book.objects.get(id=int(book_id))
def link(self):
return '/book/%s' % self.book_id
def items(self):
return self.book.comment_set.all().order_by('-createtime')[:15]
def title(self):
return 'Comments of: ' + self.book.title
def description(self):
return self.book.description
def item_link(self, item):
return '/book/%s/%s' % (self.book_id, item.chapter.num)
def item_description(self, item):
return item.content
def item_title(self, item):
return '#%d Comment for: ' % item.id + item.chapter.title
def item_pubdate(self, item):
return item.createtime
def item_author_name(self, item):
return item.username
And the view code is:
from feeds import *
from utils.easyfeed import render_feed
from utils.common import get_full_path
def bookcomments(request, book_id):
return render_feed(BookCommentsFeed(get_full_path(request), book_id))