You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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