blob: 251e1f6bb36ffbca1941757b451768802957e3c8 [file] [log] [blame]
Rushabh Mehta2e5db352013-01-16 11:34:26 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from __future__ import unicode_literals
18
19import webnotes
20from core.doctype.communication.communication import make
21
22max_communications_per_hour = 300
23
24@webnotes.whitelist(allow_guest=True)
25def send_message(subject="Website Query", message="", sender="", status="Open"):
26 if not message:
27 webnotes.response["message"] = 'Please write something'
28 return
29
30 if not sender:
31 webnotes.response["message"] = 'Email Id Required'
32 return
33
34 # make lead / communication
Rushabh Mehta176829e2013-02-11 14:54:30 +053035 from selling.doctype.lead.get_leads import add_sales_communication
Rushabh Mehta0e5401c2013-02-11 15:08:24 +053036 add_sales_communication(subject or "Website Query", message, sender, sender,
37 mail=None, status=status)
Rushabh Mehta2e5db352013-01-16 11:34:26 +053038
39 # guest method, cap max writes per hour
40 if webnotes.conn.sql("""select count(*) from `tabCommunication`
41 where TIMEDIFF(NOW(), modified) < '01:00:00'""")[0][0] > max_communications_per_hour:
42 webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
43 return
44
45 webnotes.response["message"] = 'Thank You'