Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | |
| 6 | import webnotes |
Rushabh Mehta | a0fa330 | 2013-03-22 13:02:08 +0530 | [diff] [blame] | 7 | from webnotes.utils import now |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 8 | |
| 9 | max_communications_per_hour = 300 |
| 10 | |
| 11 | @webnotes.whitelist(allow_guest=True) |
| 12 | def send_message(subject="Website Query", message="", sender="", status="Open"): |
| 13 | if not message: |
| 14 | webnotes.response["message"] = 'Please write something' |
| 15 | return |
| 16 | |
| 17 | if not sender: |
| 18 | webnotes.response["message"] = 'Email Id Required' |
| 19 | return |
| 20 | |
| 21 | # make lead / communication |
Rushabh Mehta | 176829e | 2013-02-11 14:54:30 +0530 | [diff] [blame] | 22 | from selling.doctype.lead.get_leads import add_sales_communication |
Rushabh Mehta | 46ec268 | 2013-08-29 13:53:36 +0530 | [diff] [blame] | 23 | message = add_sales_communication(subject or "Website Query", message, sender, sender, |
Rushabh Mehta | 0e5401c | 2013-02-11 15:08:24 +0530 | [diff] [blame] | 24 | mail=None, status=status) |
Rushabh Mehta | 2e5db35 | 2013-01-16 11:34:26 +0530 | [diff] [blame] | 25 | |
| 26 | # guest method, cap max writes per hour |
| 27 | if webnotes.conn.sql("""select count(*) from `tabCommunication` |
Rushabh Mehta | a0fa330 | 2013-03-22 13:02:08 +0530 | [diff] [blame] | 28 | 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] | 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 | |
Rushabh Mehta | 46ec268 | 2013-08-29 13:53:36 +0530 | [diff] [blame] | 32 | webnotes.response.status = "okay" |