Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
Rushabh Mehta | c01b7e9 | 2012-03-21 12:29:56 +0530 | [diff] [blame] | 2 | install_docs = [ |
Anand Doshi | 24e1856 | 2012-04-17 11:45:35 +0530 | [diff] [blame] | 3 | {"doctype":"Role", "role_name":"Blogger", "name":"Blogger"}, |
| 4 | {"doctype":"Role", "role_name":"Website Manager", "name":"Website Manager"}, |
| 5 | ] |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 6 | |
| 7 | import webnotes |
| 8 | |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 9 | max_tickets_per_hour = 200 |
| 10 | |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 11 | @webnotes.whitelist(allow_guest=True) |
| 12 | def send_message(): |
| 13 | from webnotes.model.doc import Document |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 14 | |
| 15 | d = Document('Support Ticket') |
| 16 | d.subject = webnotes.form_dict.get('subject', 'Website Query') |
| 17 | d.description = webnotes.form_dict.get('message') |
| 18 | d.raised_by = webnotes.form_dict.get('sender') |
Anand Doshi | e47ceae | 2012-12-24 19:50:15 +0530 | [diff] [blame] | 19 | d.status = webnotes.form_dict.get("status") or "Open" |
| 20 | |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 21 | if not d.description: |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 22 | webnotes.response["message"] = 'Please write something' |
| 23 | return |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 24 | |
| 25 | if not d.raised_by: |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 26 | webnotes.response["message"] = 'Email Id Required' |
| 27 | return |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 28 | |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 29 | # guest method, cap max writes per hour |
| 30 | if webnotes.conn.sql("""select count(*) from `tabSupport Ticket` |
| 31 | where TIMEDIFF(NOW(), modified) < '01:00:00'""")[0][0] > max_tickets_per_hour: |
| 32 | webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later" |
| 33 | return |
Rushabh Mehta | 29be189 | 2012-12-10 11:15:59 +0530 | [diff] [blame] | 34 | |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 35 | d.save() |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 36 | webnotes.response["message"] = 'Thank You' |
Anand Doshi | 7aedaec | 2012-10-16 10:47:18 +0530 | [diff] [blame] | 37 | |
| 38 | def get_site_address(): |
| 39 | from webnotes.utils import get_request_site_address |
| 40 | url = get_request_site_address() |
| 41 | |
| 42 | if not url or url=='http://localhost': |
| 43 | new_url = webnotes.conn.get_value('Website Settings', 'Website Settings', |
| 44 | 'subdomain') |
| 45 | if new_url: |
| 46 | url = "http://" + new_url |
| 47 | |
| 48 | return url |