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

126 рядки
3.6 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 webnotes
  5. from webnotes.utils import now_datetime, get_datetime_str
  6. from webnotes.webutils import get_access
  7. from webnotes.templates.website_group.settings import get_settings_context
  8. from webnotes.templates.website_group.post import get_post_context
  9. def get_views():
  10. return views
  11. def get_context(group_context):
  12. tasks_context = {}
  13. if group_context.view.name in ("open", "closed"):
  14. tasks_context["post_list_html"] = get_post_list_html(group_context["group"]["name"], group_context["view"])
  15. elif group_context.view.name == "edit":
  16. post = webnotes.doc("Post", webnotes.form_dict.name).fields
  17. tasks_context["session_user"] = webnotes.session.user
  18. tasks_context["post"] = post
  19. if post.assigned_to:
  20. tasks_context["profile"] = webnotes.doc("Profile", post.assigned_to)
  21. elif group_context.view.name == "settings":
  22. tasks_context.update(get_settings_context(group_context))
  23. elif group_context.view.name == "post":
  24. tasks_context.update(get_post_context(group_context))
  25. return tasks_context
  26. @webnotes.whitelist(allow_guest=True)
  27. def get_post_list_html(group, view, limit_start=0, limit_length=20, status="Open"):
  28. access = get_access(group)
  29. if isinstance(view, basestring):
  30. view = get_views()[view]
  31. view = webnotes._dict(view)
  32. # verify permission for paging
  33. if webnotes.local.form_dict.cmd == "get_post_list_html":
  34. if not access.get("read"):
  35. return webnotes.PermissionError
  36. if view.name=="open":
  37. now = get_datetime_str(now_datetime())
  38. order_by = "(p.upvotes + post_reply_count - (timestampdiff(hour, p.creation, \"{}\") / 2)) desc, p.creation desc".format(now)
  39. else:
  40. status = "Closed"
  41. order_by = "p.creation desc"
  42. posts = webnotes.conn.sql("""select p.*, pr.user_image, pr.first_name, pr.last_name,
  43. (select count(pc.name) from `tabPost` pc where pc.parent_post=p.name) as post_reply_count
  44. from `tabPost` p, `tabProfile` pr
  45. where p.website_group = %s and pr.name = p.owner and ifnull(p.parent_post, '')=''
  46. and p.is_task=1 and p.status=%s
  47. order by {order_by} limit %s, %s""".format(order_by=order_by),
  48. (group, status, int(limit_start), int(limit_length)), as_dict=True)
  49. context = {"posts": posts, "limit_start": limit_start, "view": view}
  50. return webnotes.get_template("templates/includes/post_list.html").render(context)
  51. views = {
  52. "open": {
  53. "name": "open",
  54. "template_path": "templates/website_group/tasks.html",
  55. "url": "/{group}",
  56. "label": "Open",
  57. "icon": "icon-inbox",
  58. "default": True,
  59. "upvote": True,
  60. "idx": 1
  61. },
  62. "closed": {
  63. "name": "closed",
  64. "template_path": "templates/website_group/tasks.html",
  65. "url": "/{group}?view=closed",
  66. "label": "Closed",
  67. "icon": "icon-smile",
  68. "idx": 2
  69. },
  70. "post": {
  71. "name": "post",
  72. "template_path": "templates/website_group/post.html",
  73. "url": "/{group}?view=post&name={post}",
  74. "label": "Post",
  75. "icon": "icon-comments",
  76. "hidden": True,
  77. "no_cache": True,
  78. "upvote": True,
  79. "idx": 3
  80. },
  81. "edit": {
  82. "name": "edit",
  83. "template_path": "templates/website_group/edit_post.html",
  84. "url": "/{group}?view=edit&name={post}",
  85. "label": "Edit Post",
  86. "icon": "icon-pencil",
  87. "hidden": True,
  88. "no_cache": True,
  89. "idx": 4
  90. },
  91. "add": {
  92. "name": "add",
  93. "template_path": "templates/website_group/edit_post.html",
  94. "url": "/{group}?view=add",
  95. "label": "Add Post",
  96. "icon": "icon-plus",
  97. "hidden": True,
  98. "idx": 5
  99. },
  100. "settings": {
  101. "name": "settings",
  102. "template_path": "templates/website_group/settings.html",
  103. "url": "/{group}?view=settings",
  104. "label": "Settings",
  105. "icon": "icon-cog",
  106. "hidden": True,
  107. "idx": 6
  108. }
  109. }