blob: be8eba6def19b58bf74d3e54cd1a2de07489f1f2 [file] [log] [blame]
Rushabh Mehta9db1a682013-04-02 10:41:37 +05301import webnotes, conf, os
Anand Doshi07f69582013-05-02 15:51:45 +05302from webnotes.utils import cint, cstr
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
37
38 if top_items and ("products" in [d.url.split(".")[0] for d in top_items if d.url]):
39 # product categories
40 products = webnotes.conn.sql("""select t1.item_group as label,
41 t2.page_name as url,
42 ifnull(t1.indent,0) as indent
43 from `tabWebsite Product Category` t1, `tabItem Group` t2
44 where t1.item_group = t2.name
45 and ifnull(t2.show_in_website,0)=1 order by t1.idx""", as_dict=1)
46 products_item = filter(lambda d: d.url and d.url.split(".")[0]=="products", top_items)[0]
47 products_item.child_items = products
48
49 ret = webnotes._dict({
50 'top_bar_items': top_items,
51 'footer_items': webnotes.conn.sql("""\
52 select * from `tabTop Bar Item`
53 where parent='Website Settings' and parentfield='footer_items'
54 order by idx asc""", as_dict=1),
55
56 'int':int,
57 "webnotes": webnotes,
58 "utils": webnotes.utils
59 })
60
61 args.update(ret)
62
63 settings = webnotes.doc("Website Settings", "Website Settings")
64 for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
Anand Doshi07f69582013-05-02 15:51:45 +053065 "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
66 "disable_signup"]:
Rushabh Mehta9db1a682013-04-02 10:41:37 +053067 if k in settings.fields:
68 args[k] = settings.fields.get(k)
69
Anand Doshi07f69582013-05-02 15:51:45 +053070 for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
71 "disable_signup"]:
72 args[k] = cint(args.get(k) or 0)
Rushabh Mehta9db1a682013-04-02 10:41:37 +053073
Anand Doshicd772da2013-05-02 17:47:17 +053074 args.url = quote(str(get_request_site_address(full_address=True)), str(""))
75 args.encoded_title = quote(str(args.title or ""), str(""))
Rushabh Mehta9db1a682013-04-02 10:41:37 +053076
77 return args
78