blob: 1041039d0e6b8464836d0f0dcc8239add605f6dc [file] [log] [blame]
Rushabh Mehta9db1a682013-04-02 10:41:37 +05301import webnotes, conf, os
2
3
4def get_templates_path():
5 return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates")
6
7standard_pages = [
8 "404", "about", "account", "attributions", "blog", "contact", "error", "index",
9 "login", "message", "order", "orders", "print", "product_search", "profile",
10 "ticket", "tickets", "writers"
11]
12
13page_map = {
14 'Web Page': webnotes._dict({
15 "template": 'html/web_page.html',
16 "condition_field": "published"
17 }),
18 'Blog Post': webnotes._dict({
19 "template": 'html/blog_page.html',
20 "condition_field": "published",
21 }),
22 'Item': webnotes._dict({
23 "template": 'html/product_page.html',
24 "condition_field": "show_in_website",
25 }),
26 'Item Group': webnotes._dict({
27 "template": "html/product_group.html",
28 "condition_field": "show_in_website"
29 })
30}
31
32page_settings_map = {
33 "about": "website.doctype.about_us_settings.about_us_settings.get_args",
34 "contact": "Contact Us Settings",
35 "blog": "website.helpers.blog.get_blog_template_args",
36 "writers": "website.helpers.blog.get_writers_args",
37 "print": "core.doctype.print_format.print_format.get_args",
38 "orders": "selling.doctype.sales_order.sales_order.get_currency_and_number_format",
39 "order": "selling.doctype.sales_order.sales_order.get_website_args",
40 "ticket": "support.doctype.support_ticket.support_ticket.get_website_args"
41}
42
43no_cache = ["message", "print", "order", "ticket"]
44
45def get_home_page():
46 doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
47 if doc_name:
48 page_name = webnotes.conn.get_value('Web Page', doc_name, 'page_name')
49 else:
50 page_name = 'login'
51
52 return page_name
53
54def update_template_args(page_name, args):
55
56 from webnotes.utils import get_request_site_address
57 from urllib import quote
58
59 all_top_items = webnotes.conn.sql("""\
60 select * from `tabTop Bar Item`
61 where parent='Website Settings' and parentfield='top_bar_items'
62 order by idx asc""", as_dict=1)
63
64 top_items = [d for d in all_top_items if not d['parent_label']]
65
66 # attach child items to top bar
67 for d in all_top_items:
68 if d['parent_label']:
69 for t in top_items:
70 if t['label']==d['parent_label']:
71 if not 'child_items' in t:
72 t['child_items'] = []
73 t['child_items'].append(d)
74 break
75
76 if top_items and ("products" in [d.url.split(".")[0] for d in top_items if d.url]):
77 # product categories
78 products = webnotes.conn.sql("""select t1.item_group as label,
79 t2.page_name as url,
80 ifnull(t1.indent,0) as indent
81 from `tabWebsite Product Category` t1, `tabItem Group` t2
82 where t1.item_group = t2.name
83 and ifnull(t2.show_in_website,0)=1 order by t1.idx""", as_dict=1)
84 products_item = filter(lambda d: d.url and d.url.split(".")[0]=="products", top_items)[0]
85 products_item.child_items = products
86
87 ret = webnotes._dict({
88 'top_bar_items': top_items,
89 'footer_items': webnotes.conn.sql("""\
90 select * from `tabTop Bar Item`
91 where parent='Website Settings' and parentfield='footer_items'
92 order by idx asc""", as_dict=1),
93
94 'int':int,
95 "webnotes": webnotes,
96 "utils": webnotes.utils
97 })
98
99 args.update(ret)
100
101 settings = webnotes.doc("Website Settings", "Website Settings")
102 for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
103 "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
104 if k in settings.fields:
105 args[k] = settings.fields.get(k)
106
107 for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
108 args[k] = int(args.get(k) or 0)
109
110 args.url = quote(str(get_request_site_address(full_address=True)), str(""))
111 args.encoded_title = quote(str(args.title or ""), str(""))
112
113 return args
114