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("")) |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 65 | args.shopping_cart_enabled = cint(webnotes.conn.get_default("shopping_cart_enabled")) |
Rushabh Mehta | 9db1a68 | 2013-04-02 10:41:37 +0530 | [diff] [blame] | 66 | |
| 67 | return args |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 68 | |
| 69 | @webnotes.whitelist() |
| 70 | def 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 | |
| 77 | def 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, |
Anand Doshi | cefccb9 | 2013-07-15 18:28:14 +0530 | [diff] [blame] | 85 | "customer": party.name}, ["mobile_no", "phone"]) |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 86 | |
| 87 | return { |
Anand Doshi | cefccb9 | 2013-07-15 18:28:14 +0530 | [diff] [blame] | 88 | "company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name), |
| 89 | "mobile_no": cstr(mobile_no), |
| 90 | "phone": cstr(phone) |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 91 | } |