blob: 20c78cae2a6425189c578e168f1b27fa769a28bb [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>
47 <pubDate>%(creation)s</pubDate>
48</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("""\
60 select page_name as name, modified, creation, title from tabBlog
61 where ifnull(published,0)=1
62 order by creation desc, modified desc, name asc limit 100""", as_dict=1)
63
64 for blog in blog_list:
65 blog.link = host + '/' + blog.name + '.html'
66 blog.content = get_blog_content(blog.name)
67
68 items += rss_item % blog
69
70 modified = max((blog['modified'] for blog in blog_list))
71
72 ws = Document('Website Settings', 'Website Settings')
73 return (rss % {
74 'title': ws.title_prefix,
75 'description': ws.description or (ws.title_prefix + ' Blog'),
76 'modified': modified,
77 'items': items,
78 'link': host + '/blog.html'
79 }).encode('utf-8', 'ignore')