def get_website_settings(): from webnotes.utils import get_request_site_address, encode, cint from urllib import quote all_top_items = webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='top_bar_items' order by idx asc""", as_dict=1) top_items = [d for d in all_top_items if not d['parent_label']] # attach child items to top bar for d in all_top_items: if d['parent_label']: for t in top_items: if t['label']==d['parent_label']: if not 'child_items' in t: t['child_items'] = [] t['child_items'].append(d) break context = webnotes._dict({ 'top_bar_items': top_items, 'footer_items': webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='footer_items' order by idx asc""", as_dict=1), "webnotes": webnotes, "utils": webnotes.utils, "post_login": [ {"label": "Reset Password", "url": "update-password", "icon": "icon-key"}, {"label": "Logout", "url": "/?cmd=web_logout", "icon": "icon-signout"} ] }) settings = webnotes.doc("Website Settings", "Website Settings") for k in ["banner_html", "brand_html", "copyright", "twitter_share_via", "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: if k in settings.fields: context[k] = settings.fields.get(k) if settings.address: context["footer_address"] = settings.address for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: context[k] = cint(context.get(k) or 0) context.url = quote(str(get_request_site_address(full_address=True)), str("")) context.encoded_title = quote(encode(context.title or ""), str("")) try: import startup.webutils if hasattr(startup.webutils, "get_website_settings"): startup.webutils.get_website_settings(context) except: pass return context
def update_template_args(page_name, args): from webnotes.utils import get_request_site_address from urllib import quote all_top_items = webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='top_bar_items' order by idx asc""", as_dict=1) top_items = [d for d in all_top_items if not d['parent_label']] # attach child items to top bar for d in all_top_items: if d['parent_label']: for t in top_items: if t['label']==d['parent_label']: if not 'child_items' in t: t['child_items'] = [] t['child_items'].append(d) break ret = webnotes._dict({ 'top_bar_items': top_items, 'footer_items': webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='footer_items' order by idx asc""", as_dict=1), 'int':int, "webnotes": webnotes, "utils": webnotes.utils }) args.update(ret) settings = webnotes.doc("Website Settings", "Website Settings") for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via", "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: if k in settings.fields: args[k] = settings.fields.get(k) for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: args[k] = cint(args.get(k) or 0) args.url = quote(str(get_request_site_address(full_address=True)), str("")) args.encoded_title = quote(encode(args.title or ""), str("")) args.shopping_cart_enabled = cint(webnotes.conn.get_default("shopping_cart_enabled")) return args
def get_website_settings(): # TODO Cache this hooks = webnotes.get_hooks() all_top_items = webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='top_bar_items' order by idx asc""", as_dict=1) top_items = [d for d in all_top_items if not d['parent_label']] # attach child items to top bar for d in all_top_items: if d['parent_label']: for t in top_items: if t['label']==d['parent_label']: if not 'child_items' in t: t['child_items'] = [] t['child_items'].append(d) break context = webnotes._dict({ 'top_bar_items': top_items, 'footer_items': webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='footer_items' order by idx asc""", as_dict=1), "post_login": [ {"label": "Reset Password", "url": "update-password", "icon": "icon-key"}, {"label": "Logout", "url": "?cmd=web_logout", "icon": "icon-signout"} ] }) settings = webnotes.doc("Website Settings", "Website Settings") for k in ["banner_html", "brand_html", "copyright", "twitter_share_via", "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: if k in settings.fields: context[k] = settings.fields.get(k) if settings.address: context["footer_address"] = settings.address for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: context[k] = cint(context.get(k) or 0) context.url = quote(str(get_request_site_address(full_address=True)), safe="/:") context.encoded_title = quote(encode(context.title or ""), str("")) for update_website_context in hooks.update_website_context or []: webnotes.get_attr(update_website_context)(context) context.web_include_js = hooks.web_include_js or [] context.web_include_css = hooks.web_include_css or [] # get settings from site config if webnotes.conf.get("fb_app_id"): context.fb_app_id = webnotes.conf.fb_app_id return context
def writerow(self, row): row = encode(row, self.encoding) self.writer.writerow(row)
def update_template_args(page_name, args): from webnotes.utils import get_request_site_address from urllib import quote all_top_items = webnotes.conn.sql( """\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='top_bar_items' order by idx asc""", as_dict=1, ) top_items = [d for d in all_top_items if not d["parent_label"]] # attach child items to top bar for d in all_top_items: if d["parent_label"]: for t in top_items: if t["label"] == d["parent_label"]: if not "child_items" in t: t["child_items"] = [] t["child_items"].append(d) break if top_items and ("products" in [d.url.split(".")[0] for d in top_items if d.url]): # product categories products = webnotes.conn.sql( """select t1.item_group as label, t2.page_name as url, ifnull(t1.indent,0) as indent from `tabWebsite Product Category` t1, `tabItem Group` t2 where t1.item_group = t2.name and ifnull(t2.show_in_website,0)=1 order by t1.idx""", as_dict=1, ) products_item = filter(lambda d: d.url and d.url.split(".")[0] == "products", top_items)[0] products_item.child_items = products ret = webnotes._dict( { "top_bar_items": top_items, "footer_items": webnotes.conn.sql( """\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='footer_items' order by idx asc""", as_dict=1, ), "int": int, "webnotes": webnotes, "utils": webnotes.utils, } ) args.update(ret) settings = webnotes.doc("Website Settings", "Website Settings") for k in [ "banner_html", "brand_html", "copyright", "address", "twitter_share_via", "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup", ]: if k in settings.fields: args[k] = settings.fields.get(k) for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup"]: args[k] = cint(args.get(k) or 0) args.url = quote(str(get_request_site_address(full_address=True)), str("")) args.encoded_title = quote(encode(args.title or ""), str("")) return args
def update_template_args(page_name, args): from webnotes.utils import get_request_site_address from urllib import quote all_top_items = webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='top_bar_items' order by idx asc""", as_dict=1) top_items = [d for d in all_top_items if not d['parent_label']] # attach child items to top bar for d in all_top_items: if d['parent_label']: for t in top_items: if t['label'] == d['parent_label']: if not 'child_items' in t: t['child_items'] = [] t['child_items'].append(d) break if top_items and ("products" in [d.url.split(".")[0] for d in top_items if d.url]): # product categories products = webnotes.conn.sql("""select t1.item_group as label, t2.page_name as url, ifnull(t1.indent,0) as indent from `tabWebsite Product Category` t1, `tabItem Group` t2 where t1.item_group = t2.name and ifnull(t2.show_in_website,0)=1 order by t1.idx""", as_dict=1) products_item = filter( lambda d: d.url and d.url.split(".")[0] == "products", top_items)[0] products_item.child_items = products ret = webnotes._dict({ 'top_bar_items': top_items, 'footer_items': webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='footer_items' order by idx asc""", as_dict=1), 'int': int, "webnotes": webnotes, "utils": webnotes.utils }) args.update(ret) settings = webnotes.doc("Website Settings", "Website Settings") for k in [ "banner_html", "brand_html", "copyright", "address", "twitter_share_via", "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup" ]: if k in settings.fields: args[k] = settings.fields.get(k) for k in [ "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup" ]: args[k] = cint(args.get(k) or 0) args.url = quote(str(get_request_site_address(full_address=True)), str("")) args.encoded_title = quote(encode(args.title or ""), str("")) return args
def update_template_args(page_name, args): from webnotes.utils import get_request_site_address from urllib import quote all_top_items = webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='top_bar_items' order by idx asc""", as_dict=1) top_items = [d for d in all_top_items if not d['parent_label']] # attach child items to top bar for d in all_top_items: if d['parent_label']: for t in top_items: if t['label'] == d['parent_label']: if not 'child_items' in t: t['child_items'] = [] t['child_items'].append(d) break ret = webnotes._dict({ 'top_bar_items': top_items, 'footer_items': webnotes.conn.sql("""\ select * from `tabTop Bar Item` where parent='Website Settings' and parentfield='footer_items' order by idx asc""", as_dict=1), 'int': int, "webnotes": webnotes, "utils": webnotes.utils }) args.update(ret) settings = webnotes.doc("Website Settings", "Website Settings") for k in [ "banner_html", "brand_html", "copyright", "address", "twitter_share_via", "favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup" ]: if k in settings.fields: args[k] = settings.fields.get(k) for k in [ "facebook_share", "google_plus_one", "twitter_share", "linked_in_share", "disable_signup" ]: args[k] = cint(args.get(k) or 0) args.url = quote(str(get_request_site_address(full_address=True)), str("")) args.encoded_title = quote(encode(args.title or ""), str("")) args.shopping_cart_enabled = cint( webnotes.conn.get_default("shopping_cart_enabled")) return args