def respond(): import webnotes import webnotes.webutils import MySQLdb try: return webnotes.webutils.render(webnotes.form_dict.get('page')) except webnotes.SessionStopped: print "Content-type: text/html" print print session_stopped % { "app_name": webnotes.get_config().app_name, "trace": webnotes.getTraceback(), "title": "Upgrading..." } except MySQLdb.ProgrammingError, e: if e.args[0]==1146: print "Content-type: text/html" print print session_stopped % { "app_name": webnotes.get_config().app_name, "trace": webnotes.getTraceback(), "title": "Installing..." } else: raise e
def respond(): import webnotes import webnotes.webutils import MySQLdb try: return webnotes.webutils.render(webnotes.form_dict.get('page')) except webnotes.SessionStopped: print "Content-type: text/html" print print session_stopped % { "app_name": webnotes.get_config().app_name, "trace": webnotes.getTraceback(), "title": "Upgrading..." } except MySQLdb.ProgrammingError, e: if e.args[0] == 1146: print "Content-type: text/html" print print session_stopped % { "app_name": webnotes.get_config().app_name, "trace": webnotes.getTraceback(), "title": "Installing..." } else: raise e
def send_login_mail(self, subject, txt, add_args): """send mail with login details""" import os from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_url full_name = get_user_fullname(webnotes.session["user"]) if full_name == "Guest": full_name = "Administrator" args = { "first_name": self.doc.first_name or self.doc.last_name or "user", "user": self.doc.name, "company": webnotes.conn.get_default("company") or webnotes.get_config().get("app_name"), "login_url": get_url(), "product": webnotes.get_config().get("app_name"), "user_fullname": full_name, } args.update(add_args) 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 send_login_mail(self, subject, txt, add_args): """send mail with login details""" import os from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_url full_name = get_user_fullname(webnotes.session['user']) if full_name == "Guest": full_name = "Administrator" args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'company': webnotes.conn.get_default('company') or webnotes.get_config().get("app_name"), 'login_url': get_url(), 'product': webnotes.get_config().get("app_name"), 'user_fullname': full_name } args.update(add_args) 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 send_login_mail(self, subject, txt, add_args): """send mail with login details""" import os from webnotes.utils.email_lib import sendmail_md from webnotes.profile import get_user_fullname from webnotes.utils import get_url full_name = get_user_fullname(webnotes.session['user']) if full_name == "Guest": full_name = "Administrator" args = { 'first_name': self.doc.first_name or self.doc.last_name or "user", 'user': self.doc.name, 'company': webnotes.conn.get_default('company') or webnotes.get_config().get("app_name"), 'login_url': get_url(), 'product': webnotes.get_config().get("app_name"), 'user_fullname': full_name } args.update(add_args) sender = webnotes.session.user not in ("Administrator", "Guest") and webnotes.session.user or None if self.doc.email: sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args) elif self.doc.number: # webnotes.errprint(self.doc.number) # msgprint(get_obj('SMS Control', 'SMS Control').send_sms(self.doc.number, txt % args)) msg = txt % args self.send_sms(msg)
def execute(): modules = webnotes.get_config().modules ml = json.loads(webnotes.conn.get_global("hidden_modules") or "[]") if len(ml) == len(modules.keys()): webnotes.conn.set_global("hidden_modules", json.dumps([]))
def build_for_framework(path, mtype, with_doctype_names=False): """make locale files for framework py and js (all)""" messages = [] for (basepath, folders, files) in os.walk(path): if 'locale' in folders: folders.remove('locale') for fname in files: fname = cstr(fname) if fname.endswith('.' + mtype): messages += get_message_list(os.path.join(basepath, fname)) # append module & doctype names if with_doctype_names: for m in webnotes.conn.sql( """select name, module from `tabDocType`"""): messages.append(m[0]) messages.append(m[1]) # append labels from config.json config = webnotes.get_config() for moduleinfo in config["modules"].values(): if moduleinfo.get("label"): messages.append(moduleinfo["label"]) if messages: write_messages_file(path, messages, mtype)
def send_welcome_mail(self): """send welcome mail to user with password and login url""" from webnotes.utils import random_string, get_url self.doc.reset_password_key = random_string(32) link = get_url("/update-password?key=" + self.doc.reset_password_key) txt = """ ## %(company)s Dear %(first_name)s, A new account has been created for you. Your login id is: %(user)s To complete your registration, please click on the link below: <a href="%(link)s">%(link)s</a> Thank you,<br> %(user_fullname)s """ self.send_login_mail("Welcome to " + webnotes.get_config().get("app_name"), txt, { "link": link })
def build_for_framework(path, mtype, with_doctype_names = False): """make locale files for framework py and js (all)""" messages = [] for (basepath, folders, files) in os.walk(path): if 'locale' in folders: folders.remove('locale') for fname in files: fname = cstr(fname) if fname.endswith('.' + mtype): messages += get_message_list(os.path.join(basepath, fname)) # append module & doctype names if with_doctype_names: for m in webnotes.conn.sql("""select name, module from `tabDocType`"""): messages.append(m[0]) messages.append(m[1]) # append labels from config.json config = webnotes.get_config() for moduleinfo in config["modules"].values(): if moduleinfo.get("label"): messages.append(moduleinfo["label"]) if messages: write_messages_file(path, messages, mtype)
def execute(): modules = webnotes.get_config().modules ml = json.loads(webnotes.conn.get_global("modules_list") or "[]") if ml: webnotes.conn.set_global("hidden_modules", json.dumps(list(set(modules.keys()).difference(set(ml)))))
def build_page(page_name): if not webnotes.conn: webnotes.connect() sitemap = get_website_sitemap() page_options = sitemap.get(page_name) if not page_options: if page_name=="index": # page not found, try home page home_page = get_home_page() page_options = sitemap.get(home_page) if not page_options: raise PageNotFoundError page_options["page_name"] = home_page else: raise PageNotFoundError else: page_options["page_name"] = page_name basepath = webnotes.utils.get_base_path() module = None no_cache = False if page_options.get("controller"): module = webnotes.get_module(page_options["controller"]) no_cache = getattr(module, "no_cache", False) # if generator, then load bean, pass arguments if page_options.get("is_generator"): if not module: raise Exception("Generator controller not defined") name = webnotes.conn.get_value(module.doctype, { page_options.get("page_name_field", "page_name"): page_options["page_name"]}) obj = webnotes.get_obj(module.doctype, name, with_children=True) if hasattr(obj, 'get_context'): obj.get_context() context = webnotes._dict(obj.doc.fields) context["obj"] = obj else: # page context = webnotes._dict({ 'name': page_name }) if module and hasattr(module, "get_context"): context.update(module.get_context()) context.update(get_website_settings()) jenv = webnotes.get_jenv() context["base_template"] = jenv.get_template(webnotes.get_config().get("base_template")) template_name = page_options['template'] html = jenv.get_template(template_name).render(context) if not no_cache: webnotes.cache().set_value("page:" + page_name, html) return html
def get_bootinfo(): """build and return boot info""" bootinfo = webnotes._dict() doclist = [] # profile get_profile(bootinfo) # control panel cp = webnotes.model.doc.getsingle('Control Panel') # system info bootinfo['control_panel'] = webnotes._dict(cp.copy()) bootinfo['sysdefaults'] = webnotes.defaults.get_defaults() bootinfo['server_date'] = webnotes.utils.nowdate() bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value( "Email Settings", None, "send_print_in_body_and_attachment") if webnotes.session['user'] != 'Guest': bootinfo['user_info'] = get_fullnames() bootinfo['sid'] = webnotes.session['sid'] # home page bootinfo.modules = webnotes.get_config().modules bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules") bootinfo.doctype_icons = dict( webnotes.conn.sql("""select name, icon from tabDocType where ifnull(icon,'')!=''""")) bootinfo.doctype_icons.update( dict( webnotes.conn.sql("""select name, icon from tabPage where ifnull(icon,'')!=''"""))) add_home_page(bootinfo, doclist) add_allowed_pages(bootinfo) load_translations(bootinfo) load_conf_settings(bootinfo) # ipinfo if webnotes.session['data'].get('ipinfo'): bootinfo['ipinfo'] = webnotes.session['data']['ipinfo'] # add docs bootinfo['docs'] = doclist # plugins try: import startup.boot startup.boot.boot_session(bootinfo) except ImportError: pass from webnotes.model.utils import compress bootinfo['docs'] = compress(bootinfo['docs']) return bootinfo
def get_portal_links(): portal_args = {} for page, opts in webnotes.get_config()["web"]["pages"].items(): if opts.get("portal"): portal_args[opts["portal"]["doctype"]] = { "page": page, "conditions": opts["portal"].get("conditions") } return portal_args
def build_page(page_name): if not webnotes.conn: webnotes.connect() sitemap_options = webnotes.doc("Website Sitemap", page_name).fields page_options = webnotes.doc( "Website Sitemap Config", sitemap_options.get("website_sitemap_config")).fields.update({ "page_name": sitemap_options.page_name, "docname": sitemap_options.docname }) if not page_options: raise PageNotFoundError else: page_options["page_name"] = page_name basepath = webnotes.utils.get_base_path() no_cache = page_options.get("no_cache") # if generator, then load bean, pass arguments if page_options.get("page_or_generator") == "Generator": doctype = page_options.get("ref_doctype") obj = webnotes.get_obj(doctype, page_options["docname"], with_children=True) if hasattr(obj, 'get_context'): obj.get_context() context = webnotes._dict(obj.doc.fields) context["obj"] = obj else: # page context = webnotes._dict({'name': page_name}) if page_options.get("controller"): module = webnotes.get_module(page_options.get("controller")) if module and hasattr(module, "get_context"): context.update(module.get_context()) context.update(get_website_settings()) jenv = webnotes.get_jenv() context["base_template"] = jenv.get_template( webnotes.get_config().get("base_template")) template_name = page_options['template_path'] html = jenv.get_template(template_name).render(context) if not no_cache: webnotes.cache().set_value("page:" + page_name, html) return html
def get_bootinfo(): """build and return boot info""" bootinfo = webnotes._dict() doclist = [] # profile get_profile(bootinfo) # control panel cp = webnotes.model.doc.getsingle('Control Panel') # system info bootinfo['control_panel'] = webnotes._dict(cp.copy()) bootinfo['sysdefaults'] = webnotes.defaults.get_defaults() bootinfo['server_date'] = webnotes.utils.nowdate() bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings", None, "send_print_in_body_and_attachment") if webnotes.session['user'] != 'Guest': bootinfo['user_info'] = get_fullnames() bootinfo['sid'] = webnotes.session['sid']; # home page bootinfo.modules = webnotes.get_config().modules bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules") bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from tabDocType where ifnull(icon,'')!=''""")) bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from tabPage where ifnull(icon,'')!=''"""))) add_home_page(bootinfo, doclist) add_allowed_pages(bootinfo) load_translations(bootinfo) load_conf_settings(bootinfo) # ipinfo if webnotes.session['data'].get('ipinfo'): bootinfo['ipinfo'] = webnotes.session['data']['ipinfo'] # add docs bootinfo['docs'] = doclist # plugins try: import startup.boot startup.boot.boot_session(bootinfo) except ImportError: pass from webnotes.model.utils import compress bootinfo['docs'] = compress(bootinfo['docs']) return bootinfo
def password_update_mail(self, password): txt = """ ## Password Update Notification Dear %(first_name)s, Your password has been updated. Here is your new password: %(new_password)s Thank you,<br> %(user_fullname)s """ self.send_login_mail("Your " + webnotes.get_config().get("app_name") + " password has been reset", txt, {"new_password": password})
def password_update_mail(self, password): txt = """ Password Update Notification Dear %(first_name)s, Your password has been updated. Here is your new password: %(new_password)s Thank you,<br> %(user_fullname)s """ self.send_login_mail("Your " + webnotes.get_config().get("app_name") + " password has been reset", txt, {"new_password": password})
def get_bootinfo(): """build and return boot info""" bootinfo = webnotes._dict() doclist = [] # profile get_profile(bootinfo) # control panel cp = webnotes.model.doc.getsingle("Control Panel") # system info bootinfo["control_panel"] = webnotes._dict(cp.copy()) bootinfo["sysdefaults"] = webnotes.defaults.get_defaults() bootinfo["server_date"] = webnotes.utils.nowdate() bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value( "Email Settings", None, "send_print_in_body_and_attachment" ) if webnotes.session["user"] != "Guest": bootinfo["user_info"] = get_fullnames() bootinfo["sid"] = webnotes.session["sid"] # home page bootinfo.modules = webnotes.get_config().modules bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules") add_home_page(bootinfo, doclist) add_allowed_pages(bootinfo) load_translations(bootinfo) load_country_and_currency(bootinfo, doclist) # ipinfo if webnotes.session["data"].get("ipinfo"): bootinfo["ipinfo"] = webnotes.session["data"]["ipinfo"] # add docs bootinfo["docs"] = doclist # plugins try: import startup.boot startup.boot.boot_session(bootinfo) except ImportError: pass from webnotes.model.utils import compress bootinfo["docs"] = compress(bootinfo["docs"]) return bootinfo
def build_page(page_name): if not webnotes.conn: webnotes.connect() sitemap_options = webnotes.doc("Website Sitemap", page_name).fields page_options = webnotes.doc("Website Sitemap Config", sitemap_options.get("website_sitemap_config")).fields.update({ "page_name":sitemap_options.page_name, "docname":sitemap_options.docname }) if not page_options: raise PageNotFoundError else: page_options["page_name"] = page_name basepath = webnotes.utils.get_base_path() no_cache = page_options.get("no_cache") # if generator, then load bean, pass arguments if page_options.get("page_or_generator")=="Generator": doctype = page_options.get("ref_doctype") obj = webnotes.get_obj(doctype, page_options["docname"], with_children=True) if hasattr(obj, 'get_context'): obj.get_context() context = webnotes._dict(obj.doc.fields) context["obj"] = obj else: # page context = webnotes._dict({ 'name': page_name }) if page_options.get("controller"): module = webnotes.get_module(page_options.get("controller")) if module and hasattr(module, "get_context"): context.update(module.get_context()) context.update(get_website_settings()) jenv = webnotes.get_jenv() context["base_template"] = jenv.get_template(webnotes.get_config().get("base_template")) template_name = page_options['template_path'] html = jenv.get_template(template_name).render(context) if not no_cache: webnotes.cache().set_value("page:" + page_name, html) return html
def password_reset_mail(self, link): """reset password""" txt = """ ## Password Reset Dear %(first_name)s, Please click on the following link to update your new password: <a href="%(link)s">%(link)s</a> Thank you,<br> %(user_fullname)s """ self.send_login_mail("Your " + webnotes.get_config().get("app_name") + " password has been reset", txt, {"link": link})
def password_reset_mail(self, link): """reset password""" txt = """ Password Reset Dear %(first_name)s, Please click on the following link to update your new password: <a href="%(link)s">%(link)s</a> Thank you,<br> %(user_fullname)s """ self.send_login_mail("Your " + webnotes.get_config().get("app_name") + " password has been reset", txt, {"link": link})
def generate(domain): global frame_xml, link_xml import urllib, os import webnotes import webnotes.webutils from webnotes.utils import nowdate # settings max_items = 1000 count = 0 site_map = '' if domain: today = nowdate() # generated pages for doctype, opts in webnotes.webutils.get_generators().items(): pages = webnotes.conn.sql("""select page_name, `modified` from `tab%s` where ifnull(%s,0)=1 order by modified desc""" % (doctype, opts.get("condition_field"))) for p in pages: if count >= max_items: break if p[0]: page_url = os.path.join(domain, urllib.quote(p[0])) modified = p[1].strftime('%Y-%m-%d') site_map += link_xml % (page_url, modified) count += 1 if count >= max_items: break # standard pages for page, opts in webnotes.get_config()["web"]["pages"].items(): if "no_cache" in opts: continue if count >= max_items: break page_url = os.path.join(domain, urllib.quote(page)) modified = today site_map += link_xml % (page_url, modified) count += 1 return frame_xml % site_map
def send_welcome_mail(self, password): """send welcome mail to user with password and login url""" txt = """ ## %(company)s Dear %(first_name)s, A new account has been created for you, here are your details: Login Id: %(user)s<br> Password: %(password)s To login to your new %(product)s account, please go to: %(login_url)s Thank you,<br> %(user_fullname)s """ self.send_login_mail("Welcome to " + webnotes.get_config().get("app_name"), txt, { "password": password })
def send_welcome_mail(self, password): """send welcome mail to user with password and login url""" txt = """ ## %(company)s Dear %(first_name)s, A new account has been created for you, here are your details: Login Id: %(user)s<br> Password: %(password)s To login to your new %(product)s account, please go to: %(login_url)s Thank you,<br> %(user_fullname)s """ self.send_login_mail( "Welcome to " + webnotes.get_config().get("app_name"), txt, {"password": password})
def get_page_settings(): return webnotes.get_config()["web"]["pages"]
def get_generators(): return webnotes.get_config()["web"]["generators"]
def get_standard_pages(): return webnotes.get_config()["web"]["pages"].keys()
def build_page(page_name): from jinja2 import Environment, FileSystemLoader from markdown2 import markdown if not webnotes.conn: webnotes.connect() sitemap = get_website_sitemap() page_options = sitemap.get(page_name) if not page_options: if page_name == "index": # page not found, try home page home_page = get_home_page() page_options = sitemap.get(home_page) if not page_options: raise PageNotFoundError page_options["page_name"] = home_page else: raise PageNotFoundError else: page_options["page_name"] = page_name basepath = webnotes.utils.get_base_path() module = None no_cache = False if page_options.get("controller"): module = webnotes.get_module(page_options["controller"]) no_cache = getattr(module, "no_cache", False) # if generator, then load bean, pass arguments if page_options.get("is_generator"): if not module: raise Exception("Generator controller not defined") name = webnotes.conn.get_value( module.doctype, {"page_name": page_options["page_name"]}) obj = webnotes.get_obj(module.doctype, name, with_children=True) if hasattr(obj, 'get_context'): obj.get_context() context = webnotes._dict(obj.doc.fields) context["obj"] = obj else: # page context = webnotes._dict({'name': page_name}) if module and hasattr(module, "get_context"): context.update(module.get_context()) context.update(get_website_settings()) jenv = Environment(loader=FileSystemLoader(basepath)) jenv.filters["markdown"] = markdown context["base_template"] = jenv.get_template( webnotes.get_config().get("base_template")) template_name = page_options['template'] html = jenv.get_template(template_name).render(context) if not no_cache: webnotes.cache().set_value("page:" + page_name, html) return html