blob: 295e5bb0cab301707c0a2bb3f16270b3c2221218 [file] [log] [blame]
Rushabh Mehta9db1a682013-04-02 10:41:37 +05301import webnotes, conf, os
2
Rushabh Mehta9db1a682013-04-02 10:41:37 +05303def get_templates_path():
4 return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates")
5
Rushabh Mehta9db1a682013-04-02 10:41:37 +05306def get_home_page():
7 doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
8 if doc_name:
9 page_name = webnotes.conn.get_value('Web Page', doc_name, 'page_name')
10 else:
11 page_name = 'login'
12
13 return page_name
14
15def update_template_args(page_name, args):
16
17 from webnotes.utils import get_request_site_address
18 from urllib import quote
19
20 all_top_items = webnotes.conn.sql("""\
21 select * from `tabTop Bar Item`
22 where parent='Website Settings' and parentfield='top_bar_items'
23 order by idx asc""", as_dict=1)
24
25 top_items = [d for d in all_top_items if not d['parent_label']]
26
27 # attach child items to top bar
28 for d in all_top_items:
29 if d['parent_label']:
30 for t in top_items:
31 if t['label']==d['parent_label']:
32 if not 'child_items' in t:
33 t['child_items'] = []
34 t['child_items'].append(d)
35 break
36
37 if top_items and ("products" in [d.url.split(".")[0] for d in top_items if d.url]):
38 # product categories
39 products = webnotes.conn.sql("""select t1.item_group as label,
40 t2.page_name as url,
41 ifnull(t1.indent,0) as indent
42 from `tabWebsite Product Category` t1, `tabItem Group` t2
43 where t1.item_group = t2.name
44 and ifnull(t2.show_in_website,0)=1 order by t1.idx""", as_dict=1)
45 products_item = filter(lambda d: d.url and d.url.split(".")[0]=="products", top_items)[0]
46 products_item.child_items = products
47
48 ret = webnotes._dict({
49 'top_bar_items': top_items,
50 'footer_items': webnotes.conn.sql("""\
51 select * from `tabTop Bar Item`
52 where parent='Website Settings' and parentfield='footer_items'
53 order by idx asc""", as_dict=1),
54
55 'int':int,
56 "webnotes": webnotes,
57 "utils": webnotes.utils
58 })
59
60 args.update(ret)
61
62 settings = webnotes.doc("Website Settings", "Website Settings")
63 for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
64 "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
65 if k in settings.fields:
66 args[k] = settings.fields.get(k)
67
68 for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
69 args[k] = int(args.get(k) or 0)
70
71 args.url = quote(str(get_request_site_address(full_address=True)), str(""))
72 args.encoded_title = quote(str(args.title or ""), str(""))
73
74 return args
75