def send_login_mail(self, subject, txt, password): """send mail with login details""" import os import startup from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_request_site_address args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'password': password, 'company': webnotes.conn.get_default('company') or startup.product_name, 'login_url': get_request_site_address(), 'product': startup.product_name, 'user_fullname': get_user_fullname(webnotes.session['user']) } sender = webnotes.session.user not in ( "Administrator", "Guest") and webnotes.session.user or None sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args)
def add_unsubscribe_link(email): from webnotes.utils import get_request_site_address return message + """<div style="padding: 7px; border-top: 1px solid #aaa; margin-top: 17px;"> <small><a href="http://%s/server.py?cmd=%s&email=%s&type=%s&email_field=%s"> Unsubscribe</a> from this list.</small></div>""" % (get_request_site_address(), 'webnotes.utils.email_lib.bulk.unsubscribe', email, doctype, email_field)
def get_context(): """generate rss feed""" host = get_request_site_address() blog_list = webnotes.conn.sql("""\ select page_name as name, published_on, modified, title, content from `tabBlog Post` where ifnull(published,0)=1 order by published_on desc limit 20""", as_dict=1) for blog in blog_list: blog.link = urllib.quote(host + '/' + blog.name + '.html') blog.content = escape_html(blog.content or "") if blog_list: modified = max((blog['modified'] for blog in blog_list)) else: modified = now() ws = webnotes.doc('Website Settings', 'Website Settings') context = { 'title': ws.title_prefix, 'description': ws.description or ((ws.title_prefix or "") + ' Blog'), 'modified': modified, 'items': blog_list, 'link': host + '/blog' } webnotes.response.content_type = "text/xml" # print context return context
def get_outer_env(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"]: if k in settings.fields: args[k] = settings.fields.get(k) for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]: args[k] = int(args.get(k) or 0) args.url = quote(str(get_request_site_address(full_address=True)), str("")) args.encoded_title = quote(str(args.title or ""), str("")) return args
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 get_dropbox_authorize_url(): sess = get_dropbox_session() request_token = sess.obtain_request_token() return_address = ( get_request_site_address(True) + "?cmd=setup.doctype.backup_manager.backup_dropbox.dropbox_callback" ) url = sess.build_authorize_url(request_token, return_address) return {"url": url, "key": request_token.key, "secret": request_token.secret}
def get_url(): from webnotes.utils import get_request_site_address url = get_request_site_address() if not url or "localhost" in url: subdomain = webnotes.conn.get_value("Website Settings", "Website Settings", "subdomain") if subdomain: if "http" not in subdomain: url = "http://" + subdomain return url
def get_site_address(): from webnotes.utils import get_request_site_address url = get_request_site_address() if not url or url == 'http://localhost': new_url = webnotes.conn.get_value('Website Settings', 'Website Settings', 'subdomain') if new_url: url = "http://" + new_url return url
def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0): """ Notify assignee that there is a change in assignment """ if not (assigned_by and owner and doc_type and doc_name): return # self assignment / closing - no message if assigned_by==owner: return from webnotes.boot import get_fullnames user_info = get_fullnames() # Search for email address in description -- i.e. assignee try: from startup import get_url url = get_url() except ImportError: from webnotes.utils import get_request_site_address url = get_request_site_address() assignment = """<a href="%s/app.html#!Form/%s/%s">%s: %s</a>""" % (url, doc_type, doc_name, doc_type, doc_name) if action=='CLOSE': if owner == webnotes.session.get('user'): arg = { 'contact': assigned_by, 'txt': "The task %s, that you assigned to %s, has been \ closed." % (assignment, user_info.get(owner, {}).get('fullname')) } else: arg = { 'contact': assigned_by, 'txt': "The task %s, that you assigned to %s, \ has been closed by %s." % (assignment, user_info.get(owner, {}).get('fullname'), user_info.get(webnotes.session.get('user'), {}).get('fullname')) } else: arg = { 'contact': owner, 'txt': "A new task, %s, has been assigned to you by %s." \ % (assignment, user_info.get(webnotes.session.get('user'), {}).get('fullname')), 'notify': notify } arg["parenttype"] = "Assignment" from utilities.page.messages import messages import json messages.post(json.dumps(arg))
def get_site_address(): from webnotes.utils import get_request_site_address url = get_request_site_address() if not url or url=='http://localhost': new_url = webnotes.conn.get_value('Website Settings', 'Website Settings', 'subdomain') if new_url: url = "http://" + new_url return url
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 add_unsubscribe_link(email): from webnotes.utils import get_request_site_address import urllib return message + """<div style="padding: 7px; border-top: 1px solid #aaa; margin-top: 17px;"> <small><a href="%s/server.py?%s"> Unsubscribe</a> from this list.</small></div>""" % (get_request_site_address(), urllib.urlencode({ "cmd": "webnotes.utils.email_lib.bulk.unsubscribe", "email": email, "type": doctype, "email_field": email_field }))
def get_dropbox_authorize_url(): sess = get_dropbox_session() request_token = sess.obtain_request_token() return_address = get_request_site_address(True) \ + "?cmd=setup.doctype.backup_manager.backup_dropbox.dropbox_callback" url = sess.build_authorize_url(request_token, return_address) return { "url": url, "key": request_token.key, "secret": request_token.secret, }
def get_context(): """generate the sitemap XML""" links = webnotes.webutils.get_website_sitemap().items() host = get_request_site_address() for l in links: l[1]["loc"] = urllib.basejoin(host, urllib.quote(l[1].get("page_name", l[1]["link_name"]).encode("utf-8"))) webnotes.response.content_type = "text/xml" return { "links": [l[1] for l in links if not l[1].get("no_sitemap")] }
def get_context(): """generate the sitemap XML""" links = webnotes.webutils.get_website_sitemap().items() host = get_request_site_address() for l in links: l[1]["loc"] = urllib.basejoin( host, urllib.quote(l[1].get("page_name", l[1]["link_name"]).encode("utf-8"))) webnotes.response.content_type = "text/xml" return {"links": [l[1] for l in links if not l[1].get("no_sitemap")]}
def get_context(context): """generate the sitemap XML""" host = get_request_site_address() links = [] for l in webnotes.conn.sql("""select `tabWebsite Sitemap`.page_name, `tabWebsite Sitemap`.lastmod from `tabWebsite Sitemap`, `tabWebsite Sitemap Config` where `tabWebsite Sitemap`.website_sitemap_config = `tabWebsite Sitemap Config`.name and ifnull(`tabWebsite Sitemap Config`.no_sitemap, 0)=0""", as_dict=True): links.append({ "loc": urllib.basejoin(host, urllib.quote(l.page_name.encode("utf-8"))), "lastmod": l.lastmod }) return {"links":links}
def get_context(): """generate the sitemap XML""" host = get_request_site_address() links = [] for l in webnotes.conn.sql( """select `tabWebsite Sitemap`.page_name, `tabWebsite Sitemap`.lastmod from `tabWebsite Sitemap`, `tabWebsite Sitemap Config` where `tabWebsite Sitemap`.website_sitemap_config = `tabWebsite Sitemap Config`.name and ifnull(`tabWebsite Sitemap Config`.no_sitemap, 0)=0""", as_dict=True): links.append({ "loc": urllib.basejoin(host, urllib.quote(l.page_name.encode("utf-8"))), "lastmod": l.lastmod }) return {"links": links}
def send_login_mail(self, subject, txt, password): """send mail with login details""" import os import startup from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_request_site_address args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'password': password, 'company': webnotes.conn.get_default('company') or startup.product_name, 'login_url': get_request_site_address(), 'product': startup.product_name, 'user_fullname': get_user_fullname(webnotes.session['user']) } sendmail_md(self.doc.email, subject=subject, msg=txt % args)
def send_login_mail(self, subject, txt, password): """send mail with login details""" import os import startup from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_request_site_address args = { "first_name": self.doc.first_name or self.doc.last_name or "user", "user": self.doc.name, "password": password, "company": webnotes.conn.get_default("company") or startup.product_name, "login_url": get_request_site_address(), "product": startup.product_name, "user_fullname": get_user_fullname(webnotes.session["user"]), } sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % 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
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 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