blob: eab4948dd347013d6592cb71c85257a392fa4c2c [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 get_home_page():
11 doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
12 if doc_name:
13 page_name = webnotes.conn.get_value('Web Page', doc_name, 'page_name')
14 else:
15 page_name = 'login'
16
17 return page_name
18
19def update_template_args(page_name, args):
20
21 from webnotes.utils import get_request_site_address
22 from urllib import quote
23
24 all_top_items = webnotes.conn.sql("""\
25 select * from `tabTop Bar Item`
26 where parent='Website Settings' and parentfield='top_bar_items'
27 order by idx asc""", as_dict=1)
28
29 top_items = [d for d in all_top_items if not d['parent_label']]
30
31 # attach child items to top bar
32 for d in all_top_items:
33 if d['parent_label']:
34 for t in top_items:
35 if t['label']==d['parent_label']:
36 if not 'child_items' in t:
37 t['child_items'] = []
38 t['child_items'].append(d)
39 break
Rushabh Mehtac382eb52013-06-11 12:03:37 +053040
Rushabh Mehta9db1a682013-04-02 10:41:37 +053041 ret = webnotes._dict({
42 'top_bar_items': top_items,
43 'footer_items': webnotes.conn.sql("""\
44 select * from `tabTop Bar Item`
45 where parent='Website Settings' and parentfield='footer_items'
46 order by idx asc""", as_dict=1),
47
48 'int':int,
49 "webnotes": webnotes,
50 "utils": webnotes.utils
51 })
52
53 args.update(ret)
54
55 settings = webnotes.doc("Website Settings", "Website Settings")
56 for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
Anand Doshi07f69582013-05-02 15:51:45 +053057 "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
58 "disable_signup"]:
Rushabh Mehta9db1a682013-04-02 10:41:37 +053059 if k in settings.fields:
60 args[k] = settings.fields.get(k)
61
Anand Doshi07f69582013-05-02 15:51:45 +053062 for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
63 "disable_signup"]:
64 args[k] = cint(args.get(k) or 0)
Rushabh Mehta9db1a682013-04-02 10:41:37 +053065
Anand Doshicd772da2013-05-02 17:47:17 +053066 args.url = quote(str(get_request_site_address(full_address=True)), str(""))
Anand Doshi488a8212013-05-22 15:51:47 +053067 args.encoded_title = quote(encode(args.title or ""), str(""))
Anand Doshi2ac0a832013-07-10 20:49:44 +053068 args.shopping_cart_enabled = cint(webnotes.conn.get_default("shopping_cart_enabled"))
Rushabh Mehta9db1a682013-04-02 10:41:37 +053069
70 return args
Anand Doshi2ac0a832013-07-10 20:49:44 +053071
72@webnotes.whitelist()
73def update_profile(fullname, password=None, company_name=None, mobile_no=None, phone=None):
74 from website.helpers.cart import update_party
75 update_party(fullname, company_name, mobile_no, phone)
76
77 from core.doctype.profile import profile
78 return profile.update_profile(fullname, password)
79
80def get_profile_args():
81 from website.helpers.cart import get_lead_or_customer
82 party = get_lead_or_customer()
83 if party.doctype == "Lead":
84 mobile_no = party.mobile_no
85 phone = party.phone
86 else:
87 mobile_no, phone = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user,
Anand Doshicefccb92013-07-15 18:28:14 +053088 "customer": party.name}, ["mobile_no", "phone"])
Anand Doshi2ac0a832013-07-10 20:49:44 +053089
90 return {
Anand Doshicefccb92013-07-15 18:28:14 +053091 "company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name),
92 "mobile_no": cstr(mobile_no),
93 "phone": cstr(phone)
Anand Doshi2ac0a832013-07-10 20:49:44 +053094 }