No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

84 líneas
2.8 KiB

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