def index(): response.view = 'nas/index.html' response.subtitle = T("Home") gform = DIV( P("Nervatura NAS Admin", _style="font-weight: bold;"), P(SPAN(T("Username: "******"font-weight: bold;"), session.auth.user.username), P(SPAN("Ver.No: " + response.verNo, _class="vernum")), TABLE( TR( TD(IMG(_style="vertical-align: bottom;", _src=URL('static', 'images/icon64_ntura_te.png')), _style="width: 64px;padding-right: 0px;"), TD("OPEN SOURCE", BR(), "BUSINESS", BR(), "MANAGEMENT", _style= "width: 120px;color: #616161;vertical-align: middle;font-size: 13px;" ))), P( A("©2011-2015 Nervatura Framework", _href="http://www.nervatura.com", _target="_blank", _title="Nervatura", _style="font-weight: bold;")), _align="center", _style="padding-top:30px;") return dict(form=gform)
def get_mobil_button(self, label, href, icon="forward", cformat="ui-btn-right", ajax="true", iconpos="left", rel=None, target=None, style=None, onclick=None, theme=None, cmd_id=None, mini=None, transition=None, position=None, title=None): cmd = A(SPAN(label), _href=href, _class=cformat) cmd["_data-role"] = "button" cmd["_data-icon"] = icon cmd["_data-ajax"] = ajax cmd["_data-iconpos"] = iconpos if title: cmd["_title"] = title if cformat: cmd["_class"] = cformat if rel: cmd["_data-rel"] = rel if target: cmd["_target"] = "_blank" if style: cmd["_style"] = style if onclick: cmd["_onclick"] = onclick if theme: cmd["_data-theme"] = theme if cmd_id: cmd["_id"] = cmd_id if mini: cmd["_data-mini"] = mini if transition: cmd["_data-transition"] = transition if position: cmd["_data-position-to"] = position return cmd
def createDatabase(): if session.auth.user.username == "demo": return P( SPAN(T("Demo user: This action is not allowed!"), _style="color:red;")) if request.vars.alias == None: return str(T("Error: Missing alias parameter!")) return P(dbtool.createDatabase(request.vars.alias))
def index(): company_name = ns.valid.get_own_customer().custname customer_count_1 = len(ns.db((ns.db.customer.deleted==0)&(ns.db.customer.custtype!=ns.valid.get_groups_id("custtype", "own"))).select().as_list()) customer_count_2 = ns.db.executesql( "select count(*) as rc from customer where deleted=0 and id not in(select customer.id from customer \ inner join groups on customer.custtype=groups.id and groups.groupvalue='own')",as_dict = True)[0]["rc"] table = TABLE(TR(TD("Database company name: "+company_name)), TR(TD("Customer count 1: "+str(customer_count_1))), TR(TD("Customer count 2: "+str(customer_count_2))), TR(TD("Secret page: ",A(SPAN("Login"), _href=URL("secret_page"), _title=T("Login..."))))) return table
def create_db(): response.subtitle = T("Database Creation") response.view = 'nas/index.html' alias = db( (db.databases.deleted == False)).select(db.databases.id, db.databases.alias, orderby=db.databases.alias) cmb_alias = SELECT( *[OPTION(field["alias"], _value=field["alias"]) for field in alias], _id="cmb_alias", _style="margin-top: 0px;") if len(cmb_alias) == 0: cmb_alias.insert(0, OPTION("", _value="")) gform = DIV( HR(), P(SPAN(T('1. Create a new database alias. See ')), A("Customer Databases", _href=URL("databases"), _style="color:#0069D6;font-style: italic;"), BR(), SPAN( T('2. The sqlite and Google SQL databases are created automatically.' )), BR(), SPAN( T('3. Other types of databases must be created manually before.') ), BR(), SPAN(T('4. Please select an alias, and start the creation:')), _style="font-style: italic;"), DIV( SPAN(T('Database alias:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_alias, P(SPAN(T('Starting the process?'), _id="msg_result", _style="font-style: italic;"), ui.control.get_mobil_button(label=T("Start"), href="#", onclick="createDatabase();", cformat=None, icon="check", theme="b", style="width: 100px;"), _style="padding-top: 0px;")), HR(), _style="font-weight: bold;", _align="left") return dict(form=gform)
def user(): table = TABLE(TR(TD("Back to home: ",A(SPAN("HOME"), _href=URL("index"), _title=T("HOME")))), TR(TD(auth()))) return table
def secret_page(): table = TABLE(TR(TD("Back to home: ",A(SPAN("HOME"), _href=URL("index"), _title=T("HOME")))), TR(TD("Change password: "******"Change password"), _href=URL("user/change_password"), _title=T("Change password...")))), TR(TD("Logout: ",A(SPAN("Exit"), _href=URL("user/logout"), _title=T("Logout..."))))) return table
def restore_backup(): response.subtitle = T("Restore the Customer Data") response.view = 'nas/index.html' msg_result = T('Starting the process?') if request.post_vars: if request.post_vars.alias == None or request.post_vars.alias == "": msg_result = T("Error: Missing alias parameter!") if request.post_vars.has_key("frm_file"): if request.post_vars.bfile == "": msg_result = T("Error: Missing upload file!") else: msg_result = dbtool.loadBackupData( alias=request.vars.alias, bfile=request.post_vars.bfile) else: if request.post_vars.filename == "": msg_result = T("Error: Missing upload filename!") else: msg_result = dbtool.loadBackupData( alias=request.vars.alias, filename=request.post_vars.filename) request.post_vars = None alias = db( (db.databases.deleted == False)).select(db.databases.id, db.databases.alias, orderby=db.databases.alias) cmb_alias = SELECT( *[OPTION(field["alias"], _value=field["alias"]) for field in alias], _name="alias", _id="cmb_alias") if len(cmb_alias) == 0: cmb_alias.insert(0, OPTION("", _value="")) dfiles = os.listdir(os.path.join(ns.request.folder, 'static/backup')) files = [] for dfile in dfiles: if str(dfile).endswith(".backup") or str(dfile).endswith(".xml"): files.append(dfile) files.sort() cmb_files = SELECT(*files, _id="cmb_files", _name="filename") if len(cmb_files) == 0: cmb_files.insert(0, OPTION("", _value="")) cmd_filename = INPUT( _type="submit", _name="frm_filename", _title=ns.T('Start restore from local backup file'), _value=T("Start restore"), _onclick="msg_result.innerHTML='" + T("Process started. Waiting for the server to respond ...") + "';") cmd_filename["_data-theme"] = "b" cmd_filename["_data-icon"] = "check" cmd_file = INPUT( _type="submit", _name="frm_file", _title=ns.T('Upload file and Start restore'), _value=T("Upload and Start restore"), _onclick="msg_result.innerHTML='" + T("Process started. Waiting for the server to respond ...") + "';") cmd_file["_data-theme"] = "b" cmd_file["_data-icon"] = "check" cmd_file["_data-ajax"] = "false" if request.env.web2py_runtime_gae: gform = DIV( HR(), P( SPAN( T('The sqlite and Google SQL databases are created automatically. Other types of databases must be created manually before.' ))), FORM(DIV( SPAN(T('Database alias:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_alias), DIV(SPAN(T('File:'), _style="padding-right: 15px;padding-left: 15px;"), INPUT(_type='file', _name='bfile', _id='bfile', _requires=IS_NOT_EMPTY()), SPAN("", _style="padding-left: 15px;"), cmd_file, _style="padding-top: 8px;"), _id="frm_upload_files", _name="frm_upload", **{"_data-ajax": "false"}), P( SPAN(msg_result, _id="msg_result", _style= "padding-left: 15px;font-style: italic;padding-top: 5px;") ), HR(), _style="font-weight: bold;", _align="left") else: gform = DIV( HR(), P( SPAN( T('The sqlite and Google SQL databases are created automatically. Other types of databases must be created manually before.' ))), FORM(DIV( SPAN(T('Database alias:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_alias), DIV(SPAN(T('Filename:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_files, SPAN("", _style="padding-left: 15px;"), cmd_filename, _style="padding-top: 8px;"), DIV(SPAN(T('File:'), _style="padding-right: 15px;padding-left: 15px;"), INPUT(_type='file', _name='bfile', _id='bfile', _requires=IS_NOT_EMPTY()), SPAN("", _style="padding-left: 15px;"), cmd_file, _style="padding-top: 8px;"), _id="frm_upload_files", _name="frm_upload", **{"_data-ajax": "false"}), P( SPAN(msg_result, _id="msg_result", _style= "padding-left: 15px;font-style: italic;padding-top: 5px;") ), HR(), _style="font-weight: bold;", _align="left") return dict(form=gform)
def create_backup(): response.subtitle = T("Create a Backup") response.view = 'nas/index.html' alias = db( (db.databases.deleted == False)).select(db.databases.id, db.databases.alias, orderby=db.databases.alias) cmb_alias = SELECT( *[OPTION(field["alias"], _value=field["alias"]) for field in alias], _id="cmb_alias") if len(cmb_alias) == 0: cmb_alias.insert(0, OPTION("", _value="")) cmb_format = SELECT( [OPTION(T("backup"), _value="backup"), OPTION(T("XML"), _value="xml")], _id="cmb_format") if len(cmb_format) == 0: cmb_format.insert(0, OPTION("", _value="")) cmb_filename = SELECT([ OPTION(T("Alias"), _value=""), OPTION(T("Download"), _value="download"), OPTION(T("Custom"), _value="custom") ], _id="cmb_filename") if request.env.web2py_runtime_gae: cmb_filename = SELECT([OPTION(T("Download"), _value="download")], _id="cmb_filename") cust_filename = "" else: cust_filename = INPUT(_type="text", _value="", _id="cust_filename") gform = DIV( HR(), P( SPAN(T('Nervatura backup: '), _style="color:brown;"), BR(), SPAN(T('NOM objects: '), _style="color:green;"), SPAN( "address, barcode, contact, currency, customer, deffield, employee, event, fieldvalue, groups, item, link, \ log, movement, numberdef, pattern, payment, place, price, product, project, rate, tax, tool, trans" ), BR(), SPAN(T('Settings objects: '), _style="color:green;"), SPAN("ui_audit, ui_language, \ ui_menu, ui_menufields, ui_message, ui_report, ui_reportfields, \ ui_reportsources, ui_userconfig"), BR(), SPAN(T('Not included: '), _style="color:red;"), SPAN("ui_printqueue"), BR(), BR(), SPAN(T( "Independent from the database type and version of the NAS server." ), _style="font-style: italic;")), DIV( DIV( SPAN(T('Database alias:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_alias), DIV(SPAN(T('Filename:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_filename, SPAN(" "), cust_filename, _style="padding-top: 10px;"), DIV(SPAN(T('Backup format:'), _style="padding-right: 15px;padding-left: 15px;"), cmb_format, _style="padding-top: 10px;"), P(SPAN(T('Starting the process?'), _id="msg_result", _style="font-style: italic;"), ui.control.get_mobil_button( label=T("Start"), href="#", onclick="createDataBackup();", cformat=None, icon="check", theme="b", style="width: 100px;", title=ns.T('Start customer backup creation')), _style="padding-top: 5px;")), HR(), _style="font-weight: bold;", _align="left") return dict(form=gform)
href="#", cformat=None, icon="plus", title=T("Install to the database..."), style="color:#8FBC8F;", theme="b", onclick= "document.getElementById('ins_cmd').value='install';document.getElementById('ins_reportkey').value='" + row["reportkey"] + "';document.getElementById('ins_database').value='" + str(frm_filter.vars.database) + "';document.forms['frm_install'].submit();") tbody.append( TR( TD(cmd_install), TD(cmd_preview), TD(cmd_edit), TD(SPAN(row["repname"], _style="font-weight: bold;"), BR(), row["description"]))) else: try: dbs_reports.remove(row["reportkey"]) except Exception: pass if dbs_reports: for reportkey in dbs_reports: cmd_preview = INPUT(_value=T("Preview"), _disabled="", _type="button") cmd_install = ui.control.get_mobil_button( T("Delete"), href="#", cformat=None,