Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 1 | # 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 | |
| 17 | from __future__ import unicode_literals |
| 18 | |
| 19 | import webnotes |
| 20 | from core.doctype.communication.communication import make |
Rushabh Mehta | a0fa330 | 2013-03-22 13:02:08 +0530 | [diff] [blame] | 21 | from webnotes.utils import now |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 22 | |
| 23 | max_communications_per_hour = 300 |
| 24 | |
| 25 | @webnotes.whitelist(allow_guest=True) |
| 26 | def 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 Mehta | 176829e | 2013-02-11 14:54:30 +0530 | [diff] [blame] | 36 | from selling.doctype.lead.get_leads import add_sales_communication |
Rushabh Mehta | 0e5401c | 2013-02-11 15:08:24 +0530 | [diff] [blame] | 37 | add_sales_communication(subject or "Website Query", message, sender, sender, |
| 38 | mail=None, status=status) |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 39 | |
| 40 | # guest method, cap max writes per hour |
| 41 | if webnotes.conn.sql("""select count(*) from `tabCommunication` |
Rushabh Mehta | a0fa330 | 2013-03-22 13:02:08 +0530 | [diff] [blame] | 42 | where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour: |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 43 | 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' |