blob: 9ce3f0a582268a4692fc5dba54e8c7f6d65f373e [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2# License: GNU General Public License v3. See license.txt
3
Rushabh Mehta9db1a682013-04-02 10:41:37 +05304import webnotes, conf, os
Anand Doshi488a8212013-05-22 15:51:47 +05305from webnotes.utils import cint, cstr, encode
Rushabh Mehta9db1a682013-04-02 10:41:37 +05306
Rushabh Mehta9db1a682013-04-02 10:41:37 +05307def get_templates_path():
8 return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates")
9
Rushabh Mehta9db1a682013-04-02 10:41:37 +053010def update_template_args(page_name, args):
11
12 from webnotes.utils import get_request_site_address
13 from urllib import quote
14
15 all_top_items = webnotes.conn.sql("""\
16 select * from `tabTop Bar Item`
17 where parent='Website Settings' and parentfield='top_bar_items'
18 order by idx asc""", as_dict=1)
19
20 top_items = [d for d in all_top_items if not d['parent_label']]
21
22 # attach child items to top bar
23 for d in all_top_items:
24 if d['parent_label']:
25 for t in top_items:
26 if t['label']==d['parent_label']:
27 if not 'child_items' in t:
28 t['child_items'] = []
29 t['child_items'].append(d)
30 break
Rushabh Mehtac382eb52013-06-11 12:03:37 +053031
Rushabh Mehta9db1a682013-04-02 10:41:37 +053032 ret = webnotes._dict({
33 'top_bar_items': top_items,
34 'footer_items': webnotes.conn.sql("""\
35 select * from `tabTop Bar Item`
36 where parent='Website Settings' and parentfield='footer_items'
37 order by idx asc""", as_dict=1),
38
39 'int':int,
40 "webnotes": webnotes,
41 "utils": webnotes.utils
42 })
43
44 args.update(ret)
45
46 settings = webnotes.doc("Website Settings", "Website Settings")
47 for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
Anand Doshi07f69582013-05-02 15:51:45 +053048 "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
49 "disable_signup"]:
Rushabh Mehta9db1a682013-04-02 10:41:37 +053050 if k in settings.fields:
51 args[k] = settings.fields.get(k)
52
Anand Doshi07f69582013-05-02 15:51:45 +053053 for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
54 "disable_signup"]:
55 args[k] = cint(args.get(k) or 0)
Rushabh Mehta9db1a682013-04-02 10:41:37 +053056
Anand Doshicd772da2013-05-02 17:47:17 +053057 args.url = quote(str(get_request_site_address(full_address=True)), str(""))
Anand Doshi488a8212013-05-22 15:51:47 +053058 args.encoded_title = quote(encode(args.title or ""), str(""))
Anand Doshi2ac0a832013-07-10 20:49:44 +053059 args.shopping_cart_enabled = cint(webnotes.conn.get_default("shopping_cart_enabled"))
Rushabh Mehta9db1a682013-04-02 10:41:37 +053060
61 return args
Anand Doshi2ac0a832013-07-10 20:49:44 +053062
63@webnotes.whitelist()
64def update_profile(fullname, password=None, company_name=None, mobile_no=None, phone=None):
Rushabh Mehtac59c4e02013-09-09 12:17:45 +053065 from selling.utils.cart import update_party
Anand Doshi2ac0a832013-07-10 20:49:44 +053066 update_party(fullname, company_name, mobile_no, phone)
67
68 from core.doctype.profile import profile
69 return profile.update_profile(fullname, password)
70
71def get_profile_args():
Rushabh Mehtac59c4e02013-09-09 12:17:45 +053072 from selling.utils.cart import get_lead_or_customer
Anand Doshi2ac0a832013-07-10 20:49:44 +053073 party = get_lead_or_customer()
74 if party.doctype == "Lead":
75 mobile_no = party.mobile_no
76 phone = party.phone
77 else:
78 mobile_no, phone = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user,
Anand Doshicefccb92013-07-15 18:28:14 +053079 "customer": party.name}, ["mobile_no", "phone"])
Anand Doshi2ac0a832013-07-10 20:49:44 +053080
81 return {
Anand Doshicefccb92013-07-15 18:28:14 +053082 "company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name),
83 "mobile_no": cstr(mobile_no),
84 "phone": cstr(phone)
Anand Doshi2ac0a832013-07-10 20:49:44 +053085 }