您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # 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. """
  23. Generate RSS feed for blog
  24. """
  25. rss = u"""<?xml version="1.0" encoding="UTF-8" ?>
  26. <rss version="2.0">
  27. <channel>
  28. <title>%(title)s</title>
  29. <description>%(description)s</description>
  30. <link>%(link)s</link>
  31. <lastBuildDate>%(modified)s</lastBuildDate>
  32. <pubDate>%(modified)s</pubDate>
  33. <ttl>1800</ttl>
  34. %(items)s
  35. </channel>
  36. </rss>"""
  37. rss_item = u"""
  38. <item>
  39. <title>%(title)s</title>
  40. <description>%(content)s</description>
  41. <link>%(link)s</link>
  42. <guid>%(name)s</guid>
  43. <pubDate>%(modified)s</pubDate>
  44. </item>"""
  45. def generate():
  46. """generate rss feed"""
  47. import webnotes, os
  48. from webnotes.model.doc import Document
  49. host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST')
  50. items = ''
  51. modified = None
  52. for blog in webnotes.conn.sql("""select name, title, content, modified, page_name
  53. from tabBlog
  54. where ifnull(published,0)=1
  55. order by modified desc limit 100""", as_dict=1):
  56. blog['link'] = host + '/' + blog['page_name'] + '.html'
  57. blog['content'] = scrub(blog['content'][:1000] or '')
  58. if not modified:
  59. modified = blog['modified']
  60. items += rss_item % blog
  61. ws = Document('Website Settings', 'Website Settings')
  62. return (rss % {
  63. 'title': ws.title_prefix,
  64. 'description': ws.description or (ws.title_prefix + ' Blog'),
  65. 'modified': modified,
  66. 'items': items,
  67. 'link': host + '/blog.html'
  68. }).encode('utf-8', 'ignore')
  69. def scrub(txt):
  70. return txt.replace('<', '&lt;').replace('>', '&gt;')