blob: 41c203e0ada33f14090915d19b3448ee702c6552 [file] [log] [blame]
Rushabh Mehtaa494b882012-12-07 12:44:45 +05301# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
2#
3# MIT License (MIT)
4#
5# Permission is hereby granted, free of charge, to any person obtaining a
6# copy of this software and associated documentation files (the "Software"),
7# to deal in the Software without restriction, including without limitation
8# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9# and/or sell copies of the Software, and to permit persons to whom the
10# Software is furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21#
22
23from __future__ import unicode_literals
24"""
25Generate RSS feed for blog
26"""
27
28rss = u"""<?xml version="1.0" encoding="UTF-8" ?>
29<rss version="2.0">
30<channel>
31 <title>%(title)s</title>
32 <description>%(description)s</description>
33 <link>%(link)s</link>
34 <lastBuildDate>%(modified)s</lastBuildDate>
35 <pubDate>%(modified)s</pubDate>
36 <ttl>1800</ttl>
37 %(items)s
38</channel>
39</rss>"""
40
41rss_item = u"""
42<item>
43 <title>%(title)s</title>
44 <description>%(content)s</description>
45 <link>%(link)s</link>
46 <guid>%(name)s</guid>
Rushabh Mehtac08e1032013-03-15 11:36:43 +053047 <pubDate>%(published_on)s</pubDate>
Rushabh Mehtaa494b882012-12-07 12:44:45 +053048</item>"""
49
50def generate():
51 """generate rss feed"""
52 import webnotes, os
53 from webnotes.model.doc import Document
54 from website.helpers.blog import get_blog_content
55
56 host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST')
57
58 items = ''
59 blog_list = webnotes.conn.sql("""\
Rushabh Mehtac08e1032013-03-15 11:36:43 +053060 select page_name as name, published_on, modified, title, content from `tabBlog Post`
Rushabh Mehtaa494b882012-12-07 12:44:45 +053061 where ifnull(published,0)=1
Rushabh Mehtac08e1032013-03-15 11:36:43 +053062 order by published_on desc limit 20""", as_dict=1)
Rushabh Mehtaa494b882012-12-07 12:44:45 +053063
64 for blog in blog_list:
65 blog.link = host + '/' + blog.name + '.html'
Rushabh Mehtaa494b882012-12-07 12:44:45 +053066
67 items += rss_item % blog
68
69 modified = max((blog['modified'] for blog in blog_list))
70
71 ws = Document('Website Settings', 'Website Settings')
72 return (rss % {
73 'title': ws.title_prefix,
74 'description': ws.description or (ws.title_prefix + ' Blog'),
75 'modified': modified,
76 'items': items,
77 'link': host + '/blog.html'
78 }).encode('utf-8', 'ignore')