2013-08-05 09:29:54 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
2013-01-16 06:04:26 +00:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import webnotes
|
2013-03-22 07:32:08 +00:00
|
|
|
from webnotes.utils import now
|
2013-01-16 06:04:26 +00:00
|
|
|
|
|
|
|
max_communications_per_hour = 300
|
|
|
|
|
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def send_message(subject="Website Query", message="", sender="", status="Open"):
|
|
|
|
if not message:
|
|
|
|
webnotes.response["message"] = 'Please write something'
|
|
|
|
return
|
|
|
|
|
|
|
|
if not sender:
|
|
|
|
webnotes.response["message"] = 'Email Id Required'
|
|
|
|
return
|
|
|
|
|
|
|
|
# make lead / communication
|
2013-02-11 09:24:30 +00:00
|
|
|
from selling.doctype.lead.get_leads import add_sales_communication
|
2013-08-29 08:23:36 +00:00
|
|
|
message = add_sales_communication(subject or "Website Query", message, sender, sender,
|
2013-02-11 09:38:24 +00:00
|
|
|
mail=None, status=status)
|
2013-01-16 06:04:26 +00:00
|
|
|
|
|
|
|
# guest method, cap max writes per hour
|
|
|
|
if webnotes.conn.sql("""select count(*) from `tabCommunication`
|
2013-03-22 07:32:08 +00:00
|
|
|
where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour:
|
2013-01-16 06:04:26 +00:00
|
|
|
webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
|
|
|
|
return
|
|
|
|
|
2013-08-29 08:23:36 +00:00
|
|
|
webnotes.response.status = "okay"
|