Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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