blob: 4c1f5283e1cc6c72af04ca850108f7546d51a7cc [file] [log] [blame]
Rushabh Mehta9db1a682013-04-02 10:41:37 +05301import webnotes, conf, os
Anand Doshi488a8212013-05-22 15:51:47 +05302from webnotes.utils import cint, cstr, encode
Rushabh Mehta9db1a682013-04-02 10:41:37 +05303
Rushabh Mehta9db1a682013-04-02 10:41:37 +05304def get_templates_path():
5 return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates")
6
Rushabh Mehta9db1a682013-04-02 10:41:37 +05307def get_home_page():
8 doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
9 if doc_name:
10 page_name = webnotes.conn.get_value('Web Page', doc_name, 'page_name')
11 else:
12 page_name = 'login'
13
14 return page_name
15
16def update_template_args(page_name, args):
17
18 from webnotes.utils import get_request_site_address
19 from urllib import quote
20
21 all_top_items = webnotes.conn.sql("""\
22 select * from `tabTop Bar Item`
23 where parent='Website Settings' and parentfield='top_bar_items'
24 order by idx asc""", as_dict=1)
25
26 top_items = [d for d in all_top_items if not d['parent_label']]
27
28 # attach child items to top bar
29 for d in all_top_items:
30 if d['parent_label']:
31 for t in top_items:
32 if t['label']==d['parent_label']:
33 if not 'child_items' in t:
34 t['child_items'] = []
35 t['child_items'].append(d)
36 break
Rushabh Mehtac382eb52013-06-11 12:03:37 +053037
Rushabh Mehta9db1a682013-04-02 10:41:37 +053038 ret = webnotes._dict({
39 'top_bar_items': top_items,
40 'footer_items': webnotes.conn.sql("""\
41 select * from `tabTop Bar Item`
42 where parent='Website Settings' and parentfield='footer_items'
43 order by idx asc""", as_dict=1),
44
45 'int':int,
46 "webnotes": webnotes,
47 "utils": webnotes.utils
48 })
49
50 args.update(ret)
51
52 settings = webnotes.doc("Website Settings", "Website Settings")
53 for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
Anand Doshi07f69582013-05-02 15:51:45 +053054 "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
55 "disable_signup"]:
Rushabh Mehta9db1a682013-04-02 10:41:37 +053056 if k in settings.fields:
57 args[k] = settings.fields.get(k)
58
Anand Doshi07f69582013-05-02 15:51:45 +053059 for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
60 "disable_signup"]:
61 args[k] = cint(args.get(k) or 0)
Rushabh Mehta9db1a682013-04-02 10:41:37 +053062
Anand Doshicd772da2013-05-02 17:47:17 +053063 args.url = quote(str(get_request_site_address(full_address=True)), str(""))
Anand Doshi488a8212013-05-22 15:51:47 +053064 args.encoded_title = quote(encode(args.title or ""), str(""))
Anand Doshi2ac0a832013-07-10 20:49:44 +053065 args.shopping_cart_enabled = cint(webnotes.conn.get_default("shopping_cart_enabled"))
Rushabh Mehta9db1a682013-04-02 10:41:37 +053066
67 return args
Anand Doshi2ac0a832013-07-10 20:49:44 +053068
69@webnotes.whitelist()
70def update_profile(fullname, password=None, company_name=None, mobile_no=None, phone=None):
71 from website.helpers.cart import update_party
72 update_party(fullname, company_name, mobile_no, phone)
73
74 from core.doctype.profile import profile
75 return profile.update_profile(fullname, password)
76
77def get_profile_args():
78 from website.helpers.cart import get_lead_or_customer
79 party = get_lead_or_customer()
80 if party.doctype == "Lead":
81 mobile_no = party.mobile_no
82 phone = party.phone
83 else:
84 mobile_no, phone = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user,
85 "customer": party.name})
86
87 return {
88 "company_name": party.customer_name if party.doctype == "Customer" else party.company_name,
89 "mobile_no": mobile_no,
90 "phone": phone
91 }