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.
 
 
 
 
 
 

58 wiersze
1.7 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. import webnotes
  4. import webnotes.utils, markdown2
  5. from webnotes import _
  6. @webnotes.whitelist(allow_guest=True)
  7. def add_comment(args=None):
  8. """
  9. args = {
  10. 'comment': '',
  11. 'comment_by': '',
  12. 'comment_by_fullname': '',
  13. 'comment_doctype': '',
  14. 'comment_docname': '',
  15. 'page_name': '',
  16. }
  17. """
  18. if not args:
  19. args = webnotes.local.form_dict
  20. args['doctype'] = "Comment"
  21. page_name = args.get("page_name")
  22. if "page_name" in args:
  23. del args["page_name"]
  24. if "cmd" in args:
  25. del args["cmd"]
  26. comment = webnotes.bean(args)
  27. comment.ignore_permissions = True
  28. comment.insert()
  29. # since comments are embedded in the page, clear the web cache
  30. webnotes.webutils.clear_cache(page_name)
  31. # notify commentors
  32. commentors = [d[0] for d in webnotes.conn.sql("""select comment_by from tabComment where
  33. comment_doctype=%s and comment_docname=%s and
  34. ifnull(unsubscribed, 0)=0""", (comment.doc.comment_doctype, comment.doc.comment_docname))]
  35. owner = webnotes.conn.get_value(comment.doc.comment_doctype, comment.doc.comment_docname, "owner")
  36. from webnotes.utils.email_lib.bulk import send
  37. send(recipients=list(set(commentors + [owner])),
  38. doctype='Comment',
  39. email_field='comment_by',
  40. subject='New Comment on %s: %s' % (comment.doc.comment_doctype,
  41. comment.doc.title or comment.doc.comment_docname),
  42. message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args,
  43. ref_doctype=comment.doc.comment_doctype, ref_docname=comment.doc.comment_docname)
  44. template = webnotes.get_template("templates/includes/comment.html")
  45. return template.render({"comment": comment.doc.fields})