Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

66 righe
2.4 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. @webnotes.whitelist(allow_guest=True)
  8. def get_post_list_html(group, view, limit_start=0, limit_length=20):
  9. from webnotes.templates.generators.website_group import get_views
  10. # verify permission for paging
  11. if webnotes.local.form_dict.cmd == "get_post_list_html":
  12. pathname = webnotes.conn.get_value("Website Sitemap",
  13. {"ref_doctype": "Website Group", "docname": group})
  14. access = get_access(pathname)
  15. if not access.get("read"):
  16. return webnotes.PermissionError
  17. conditions = ""
  18. values = [group]
  19. group_type = webnotes.conn.get_value("Website Group", group, "group_type")
  20. if group_type == "Events":
  21. # should show based on time upto precision of hour
  22. # because the current hour should also be in upcoming
  23. values.append(now_datetime().replace(minute=0, second=0, microsecond=0))
  24. if view in ("feed", "closed"):
  25. order_by = "p.creation desc"
  26. if view == "closed":
  27. conditions += " and p.is_task=1 and p.status='Closed'"
  28. elif view in ("popular", "open"):
  29. now = get_datetime_str(now_datetime())
  30. order_by = """(p.upvotes + post_reply_count - (timestampdiff(hour, p.creation, \"{}\") / 2)) desc,
  31. p.creation desc""".format(now)
  32. if view == "open":
  33. conditions += " and p.is_task=1 and p.status='Open'"
  34. elif view == "upcoming":
  35. conditions += " and p.is_event=1 and p.event_datetime >= %s"
  36. order_by = "p.event_datetime asc"
  37. elif view == "past":
  38. conditions += " and p.is_event=1 and p.event_datetime < %s"
  39. order_by = "p.event_datetime desc"
  40. values += [int(limit_start), int(limit_length)]
  41. posts = webnotes.conn.sql("""select p.*, pr.user_image, pr.first_name, pr.last_name,
  42. (select count(pc.name) from `tabPost` pc where pc.parent_post=p.name) as post_reply_count
  43. from `tabPost` p, `tabProfile` pr
  44. where p.website_group = %s and pr.name = p.owner and ifnull(p.parent_post, '')=''
  45. {conditions} order by {order_by} limit %s, %s""".format(conditions=conditions, order_by=order_by),
  46. tuple(values), as_dict=True, debug=True)
  47. context = { "posts": posts, "limit_start": limit_start, "view": get_views(group_type)[view] }
  48. return webnotes.get_template("templates/includes/post_list.html").render(context)