Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

71 linhas
2.3 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import markdown2
  5. import webnotes
  6. from webnotes.utils import global_date_format, get_fullname, cint
  7. doctype = "Blog Post"
  8. condition_field = "published"
  9. def get_context(context):
  10. blog_post = context.bean.doc
  11. # this is for double precaution. usually it wont reach this code if not published
  12. if not cint(blog_post.published):
  13. raise Exception, "This blog has not been published yet!"
  14. # temp fields
  15. blog_post.full_name = get_fullname(blog_post.owner)
  16. blog_post.updated = global_date_format(blog_post.published_on)
  17. if blog_post.blogger:
  18. blog_post.blogger_info = webnotes.doc("Blogger", blog_post.blogger).fields
  19. blog_post.description = blog_post.blog_intro or blog_post.content[:140]
  20. blog_post.meta_description = blog_post.description
  21. blog_post.categories = webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
  22. blog_post.comment_list = webnotes.conn.sql("""\
  23. select comment, comment_by_fullname, creation
  24. from `tabComment` where comment_doctype="Blog Post"
  25. and comment_docname=%s order by creation""", (blog_post.name,), as_dict=1) or []
  26. return blog_post.fields
  27. @webnotes.whitelist(allow_guest=True)
  28. def get_blog_list(start=0, by=None, category=None):
  29. condition = ""
  30. if by:
  31. condition = " and t1.blogger='%s'" % by.replace("'", "\'")
  32. if category:
  33. condition += " and t1.blog_category='%s'" % category.replace("'", "\'")
  34. query = """\
  35. select
  36. t1.title, t1.name, t1.page_name, t1.published_on as creation,
  37. ifnull(t1.blog_intro, t1.content) as content,
  38. t2.full_name, t2.avatar, t1.blogger,
  39. (select count(name) from `tabComment` where
  40. comment_doctype='Blog Post' and comment_docname=t1.name) as comments
  41. from `tabBlog Post` t1, `tabBlogger` t2
  42. where ifnull(t1.published,0)=1
  43. and t1.blogger = t2.name
  44. %(condition)s
  45. order by published_on desc, name asc
  46. limit %(start)s, 20""" % {"start": start, "condition": condition}
  47. result = webnotes.conn.sql(query, as_dict=1)
  48. # strip html tags from content
  49. for res in result:
  50. res['published'] = global_date_format(res['creation'])
  51. if not res['content']:
  52. res['content'] = webnotes.webutils.get_html(res['page_name'])
  53. res['content'] = res['content'][:140]
  54. return result