# -*- coding: utf-8 -*-
from django.conf import settings
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from blog.models import Article
from .constants import SYNC_STATUS
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 LatestArticleFeed(Feed):
feed_type = ExtendedRSSFeed
title = settings.WEBSITE_NAME
link = settings.WEBSITE_URL
author = settings.WEBSITE_NAME
description = settings.WEBSITE_DESC + u"关注python、django、vim、linux、web开发和互联网"
def items(self):
return Article.objects.filter(hided=False, published=True, sync_status=SYNC_STATUS.SYNCED).order_by('-publish_date')[:10]
def item_extra_kwargs(self, item):
return {'content_encoded': self.item_content_encoded(item)}
def item_title(self, item):
return item.title
# item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return '/article/%s/' % item.slug
def item_description(self, item):
return item.description
def item_author_name(self, item):
return item.creator.get_full_name()
def item_pubdate(self, item):
return item.publish_date
def item_content_encoded(self, item):
return item.content
from django import VERSION if VERSION[0: 2] > (1, 3): from django.conf.urls import patterns, include, url else: from django.conf.urls.defaults import patterns, include, url from .feeds import LatestArticleFeed urlpatterns = patterns( '', url(r'^feed/$', LatestArticleFeed()), )
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有