[website] [minor] moving to framework
This commit is contained in:
parent
1be588ca5f
commit
4014c2d336
4 changed files with 56 additions and 4 deletions
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"creation": "2013-02-21 20:12:42",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-07-05 14:32:24",
|
||||
"modified": "2013-09-11 18:43:20",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
|
|
@ -76,6 +76,13 @@
|
|||
"fieldtype": "Small Text",
|
||||
"label": "Query Options"
|
||||
},
|
||||
{
|
||||
"description": "Send enquiries to this email address",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "forward_to_email",
|
||||
"fieldtype": "Data",
|
||||
"label": "Forward To Email Address"
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ $(document).ready(function() {
|
|||
}
|
||||
|
||||
$("#contact-alert").toggle(false);
|
||||
erpnext.send_message({
|
||||
wn.send_message({
|
||||
subject: $('[name="subject"]').val(),
|
||||
sender: email,
|
||||
message: message,
|
||||
|
|
@ -34,7 +34,7 @@ $(document).ready(function() {
|
|||
}
|
||||
$(':input').val('');
|
||||
}
|
||||
});
|
||||
}, this);
|
||||
return false;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
||||
# MIT License. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import webnotes
|
||||
from webnotes.utils import now
|
||||
|
||||
def get_context():
|
||||
bean = webnotes.bean("Contact Us Settings", "Contact Us Settings")
|
||||
|
|
@ -14,3 +20,32 @@ def get_context():
|
|||
"heading": bean.doc.heading,
|
||||
"introduction": bean.doc.introduction
|
||||
}
|
||||
|
||||
|
||||
max_communications_per_hour = 300
|
||||
|
||||
@webnotes.whitelist(allow_guest=True)
|
||||
def send_message(subject="Website Query", message="", sender=""):
|
||||
if not message:
|
||||
webnotes.response["message"] = 'Please write something'
|
||||
return
|
||||
|
||||
if not sender:
|
||||
webnotes.response["message"] = 'Email Id Required'
|
||||
return
|
||||
|
||||
# guest method, cap max writes per hour
|
||||
if webnotes.conn.sql("""select count(*) from `tabCommunication`
|
||||
where TIMEDIFF(%s, modified) < '01:00:00'""", now())[0][0] > max_communications_per_hour:
|
||||
webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
|
||||
return
|
||||
|
||||
# send email
|
||||
forward_to_email = webnotes.conn.get_value("Contact Us Settings", None, "forward_to_email")
|
||||
if forward_to_email:
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
sendmail(forward_to_email, sender, message, subject)
|
||||
|
||||
webnotes.response.status = "okay"
|
||||
|
||||
return True
|
||||
|
|
@ -188,4 +188,14 @@ $(document).ready(function() {
|
|||
window.full_name = getCookie("full_name");
|
||||
$("#website-login").toggleClass("hide", full_name ? true : false);
|
||||
$("#website-post-login").toggleClass("hide", full_name ? false : true);
|
||||
});
|
||||
});
|
||||
|
||||
wn.send_message = function(opts, btn) {
|
||||
return wn.call({
|
||||
type: "POST",
|
||||
method: "website.doctype.contact_us_settings.templates.pages.contact.send_message",
|
||||
btn: btn,
|
||||
args: opts,
|
||||
callback: opts.callback
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue