blob: bf1521ee11ecc41e08ed51f33b16c9e99b6a0e0e [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
Rushabh Mehtaa0fa3302013-03-22 13:02:08 +053021from webnotes.utils import now
Rushabh Mehta2e5db352013-01-16 11:34:26 +053022
23max_communications_per_hour = 300
24
25@webnotes.whitelist(allow_guest=True)
26def send_message(subject="Website Query", message="", sender="", status="Open"):
27 if not message:
28 webnotes.response["message"] = 'Please write something'
29 return
30
31 if not sender:
32 webnotes.response["message"] = 'Email Id Required'
33 return
34
35 # make lead / communication
Rushabh Mehta176829e2013-02-11 14:54:30 +053036 from selling.doctype.lead.get_leads import add_sales_communication
Rushabh Mehta0e5401c2013-02-11 15:08:24 +053037 add_sales_communication(subject or "Website Query", message, sender, sender,
38 mail=None, status=status)
Rushabh Mehta2e5db352013-01-16 11:34:26 +053039
40 # guest method, cap max writes per hour
41 if webnotes.conn.sql("""select count(*) from `tabCommunication`
Rushabh Mehtaa0fa3302013-03-22 13:02:08 +053042 where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour:
Rushabh Mehta2e5db352013-01-16 11:34:26 +053043 webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
44 return
45
46 webnotes.response["message"] = 'Thank You'