Задать вопрос

Тел: +7 965 3737 888





EasyFeed class

<p>This class simplies the Feed class of django. The differences are:</p>
<ol><li>Don't need define title and description template file</li>
<li>default feed generator class is Atom1Feed</li>
<li>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 <a href="http://foothold.ru/knowledge/detail/get-the-full-request-path.html">Get the full request path</a> to get the full path of the feed url.)</li>
<li>There is a helper function render_feed() to return a response value.</li>
<p>Feed class:</p>
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

<p>And the view code is:</p>
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))

Вопрос полезен? Да0/Нет0