Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 1 | import webnotes, conf, os |
Anand Doshi | 488a821 | 2013-05-22 15:51:47 +0530 | [diff] [blame] | 2 | from webnotes.utils import cint, cstr, encode |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 3 | |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 4 | def get_templates_path(): |
| 5 | return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates") |
| 6 | |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 7 | def 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 | |
| 16 | def 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 Mehta | c382eb5 | 2013-06-11 12:03:37 +0530 | [diff] [blame] | 37 | |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 38 | 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 Doshi | 07f6958 | 2013-05-02 15:51:45 +0530 | [diff] [blame] | 54 | "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", |
| 55 | "disable_signup"]: |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 56 | if k in settings.fields: |
| 57 | args[k] = settings.fields.get(k) |
| 58 | |
Anand Doshi | 07f6958 | 2013-05-02 15:51:45 +0530 | [diff] [blame] | 59 | 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 Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 62 | |
Anand Doshi | cd772da | 2013-05-02 17:47:17 +0530 | [diff] [blame] | 63 | args.url = quote(str(get_request_site_address(full_address=True)), str("")) |
Anand Doshi | 488a821 | 2013-05-22 15:51:47 +0530 | [diff] [blame] | 64 | args.encoded_title = quote(encode(args.title or ""), str("")) |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 65 | |
| 66 | return args |
| 67 | |