Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

blog_post.py 2.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = webnotes.doc(context.ref_doctype, context.docname)
  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. blog_post.fields.update(context)
  27. return { "title": blog_post.title, "content": context.template.render(blog_post.fields) }
  28. @webnotes.whitelist(allow_guest=True)
  29. def get_blog_list(start=0, by=None, category=None):
  30. condition = ""
  31. if by:
  32. condition = " and t1.blogger='%s'" % by.replace("'", "\'")
  33. if category:
  34. condition += " and t1.blog_category='%s'" % category.replace("'", "\'")
  35. query = """\
  36. select
  37. t1.title, t1.name, t1.page_name, t1.published_on as creation,
  38. ifnull(t1.blog_intro, t1.content) as content,
  39. t2.full_name, t2.avatar, t1.blogger,
  40. (select count(name) from `tabComment` where
  41. comment_doctype='Blog Post' and comment_docname=t1.name) as comments
  42. from `tabBlog Post` t1, `tabBlogger` t2
  43. where ifnull(t1.published,0)=1
  44. and t1.blogger = t2.name
  45. %(condition)s
  46. order by published_on desc, name asc
  47. limit %(start)s, 20""" % {"start": start, "condition": condition}
  48. result = webnotes.conn.sql(query, as_dict=1)
  49. # strip html tags from content
  50. for res in result:
  51. res['published'] = global_date_format(res['creation'])
  52. if not res['content']:
  53. res['content'] = webnotes.webutils.get_html(res['page_name'])
  54. res['content'] = res['content'][:140]
  55. return result