-
Notifications
You must be signed in to change notification settings - Fork 3
/
feeds.py
55 lines (41 loc) · 1.65 KB
/
feeds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#coding:utf-8
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from blog.models import Post
class ExtendedRSSFeed(Rss201rev2Feed):
mime_type = 'application/xml'
"""
Create a type of RSS feed that has content:encoded elements.
"""
def root_attributes(self):
attrs = super(ExtendedRSSFeed, self).root_attributes()
attrs['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/'
return attrs
def add_item_elements(self, handler, item):
super(ExtendedRSSFeed, self).add_item_elements(handler, item)
handler.addQuickElement(u'content:encoded', item['content_encoded'])
class LatestEntriesFeed(Feed):
feed_type = ExtendedRSSFeed
# Elements for the top-level, channel.
title = u"the5fire的技术博客"
link = "http://www.the5fire.com"
author = 'the5fire'
description = u"关注python、vim、linux、web开发和互联网--life is short, we need python."
def items(self):
return Post.objects.filter(status=0).order_by('-create_time')[:10]
def item_extra_kwargs(self, item):
return {'content_encoded': self.item_content_encoded(item)}
# Elements for each item.
def item_title(self, item):
return item.title
def item_description(self, item):
return item.content_html
def item_author_name(self, item):
if (item.author.get_full_name()):
return item.author.get_full_name()
else:
return item.author
def item_pubdate(self, item):
return item.create_time
def item_content_encoded(self, item):
return item.content_html