您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

54 行
1.7 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
  6. from webnotes.webutils import render_blocks
  7. def get_context(context):
  8. bean = webnotes.bean("Contact Us Settings", "Contact Us Settings")
  9. query_options = filter(None, bean.doc.query_options.replace(",", "\n").split()) if \
  10. bean.doc.query_options else ["Sales", "Support", "General"]
  11. address = webnotes.bean("Address", bean.doc.address).doc if bean.doc.address else None
  12. contact_context = {
  13. "query_options": query_options,
  14. "address": address,
  15. "heading": bean.doc.heading,
  16. "introduction": bean.doc.introduction
  17. }
  18. contact_context.update(context)
  19. return render_blocks(contact_context)
  20. max_communications_per_hour = 300
  21. @webnotes.whitelist(allow_guest=True)
  22. def send_message(subject="Website Query", message="", sender=""):
  23. if not message:
  24. webnotes.response["message"] = 'Please write something'
  25. return
  26. if not sender:
  27. webnotes.response["message"] = 'Email Id Required'
  28. return
  29. # guest method, cap max writes per hour
  30. if webnotes.conn.sql("""select count(*) from `tabCommunication`
  31. where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour:
  32. webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
  33. return
  34. # send email
  35. forward_to_email = webnotes.conn.get_value("Contact Us Settings", None, "forward_to_email")
  36. if forward_to_email:
  37. from webnotes.utils.email_lib import sendmail
  38. sendmail(forward_to_email, sender, message, subject)
  39. webnotes.response.status = "okay"
  40. return True