Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 webnotes
  5. from webnotes.utils import get_fullname
  6. def get_post_context(group_context):
  7. post = webnotes.doc("Post", webnotes.form_dict.name)
  8. if post.parent_post:
  9. raise webnotes.PermissionError
  10. def _get_post_context():
  11. fullname = get_fullname(post.owner)
  12. return {
  13. "title": "{} by {}".format(post.title, fullname),
  14. # "group_title": group_context.get("unit_title") + " by {}".format(fullname),
  15. "parent_post_html": get_parent_post_html(post, group_context.get("view")),
  16. "post_list_html": get_child_posts_html(post, group_context.get("view")),
  17. "parent_post": post.name
  18. }
  19. cache_key = "website_group_post:".format(post.name)
  20. return webnotes.cache().get_value(cache_key, lambda: _get_post_context())
  21. def get_parent_post_html(post, view):
  22. profile = webnotes.bean("Profile", post.owner).doc
  23. for fieldname in ("first_name", "last_name", "user_image", "fb_hometown", "fb_location"):
  24. post.fields[fieldname] = profile.fields[fieldname]
  25. return webnotes.get_template("templates/includes/inline_post.html")\
  26. .render({"post": post.fields, "view": view})
  27. def get_child_posts_html(post, view):
  28. posts = webnotes.conn.sql("""select p.*, pr.user_image, pr.first_name, pr.last_name
  29. from tabPost p, tabProfile pr
  30. where p.parent_post=%s and pr.name = p.owner
  31. order by p.creation asc""", (post.name,), as_dict=True)
  32. return webnotes.get_template("templates/includes/post_list.html")\
  33. .render({
  34. "posts": posts,
  35. "parent_post": post.name,
  36. "view": view
  37. })
  38. def clear_post_cache(post=None):
  39. cache = webnotes.cache()
  40. posts = [post] if post else webnotes.conn.sql_list("select name from `tabPost`")
  41. for post in posts:
  42. cache.delete_value("website_group_post:{}".format(post))