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.
 
 
 
 
 
 

52 Zeilen
1.5 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. import frappe.utils
  6. from frappe.website.render import clear_cache
  7. from frappe import _
  8. @frappe.whitelist(allow_guest=True)
  9. def add_comment(comment, comment_email, comment_by, reference_doctype, reference_name, route):
  10. doc = frappe.get_doc(reference_doctype, reference_name)
  11. comment = doc.add_comment(
  12. text = comment,
  13. comment_email = comment_email,
  14. comment_by = comment_by)
  15. blacklist = ['http://', 'https://', '@gmail.com']
  16. if not any([b in comment.content for b in blacklist]):
  17. # probably not spam!
  18. comment.db_set('published', 1)
  19. # since comments are embedded in the page, clear the web cache
  20. if route:
  21. clear_cache(route)
  22. content = (doc.content
  23. + "<p><a href='{0}/desk/#Form/Comment/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
  24. doc.name,
  25. _("View Comment")))
  26. # notify creator
  27. frappe.sendmail(
  28. recipients = frappe.db.get_value('User', doc.owner, 'email') or doc.owner,
  29. subject = _('New Comment on {0}: {1}').format(doc.doctype, doc.name),
  30. message = content,
  31. reference_doctype=doc.doctype,
  32. reference_name=doc.name
  33. )
  34. if comment.published:
  35. # revert with template if all clear (no backlinks)
  36. template = frappe.get_template("templates/includes/comments/comment.html")
  37. return template.render({"comment": comment.as_dict()})
  38. else:
  39. return ''