def databaseDumpExec(): try: if request.vars['massive_desasignation']=="ok": # Get all students asigned laptops sql="SELECT id_laptop FROM laptops_historical lh" sql=sql+" WHERE lh.id_state=2 AND lh.id_user_type=2" sql=sql+" AND lh.id_historical IN (SELECT MAX(lh2.id_historical) FROM laptops_historical lh2 WHERE lh2.id_laptop=lh.id_laptop)" sql=sql+" GROUP BY id_laptop" sql=sql+" ORDER BY id_laptop" result = cdb.executesql(sql) for r in result: lh = LaptopsHistory(cdb,"",r[0],1,"","","","","Desasignación masiva ControlIES","") lh.add() except: pass l=conecta() t = Thinclients(l) result = t.getAllComputers() for c in result["computers"]: computer_name = c["cn"].strip() serial = c["serial"].replace("serial-number","").strip() username = c["username"].replace("user-name","").strip() mac = c["mac"].replace("ethernet","").strip() macWlan = c["macWlan"].replace("ethernet","").strip() if serial!="": id_laptop = Laptops(cdb,"","","","","","","","").existsSerialNumber(serial) if id_laptop: addHistory(l,username,id_laptop,computer_name) lap = Laptops(cdb,id_laptop,"","","","","","","") laptop = lap.getLaptopData() if laptop["mac_eth0"]!=mac or laptop["mac_wlan0"]!=macWlan: lap.updateMAC(mac,macWlan) else: # Si no existe el portatil try: if request.vars['add_laptop']=="ok": lap = Laptops(cdb,"", serial, "", "", "", "", mac, macWlan) lap.add() addHistory(l,username,lap.getIdLaptop(),computer_name) except: pass l.close() return dict(response = "OK")
def addLaptop(): serialNumber = request.vars["serial_number"].strip() l = Laptops(cdb,"", serialNumber, request.vars["name"], request.vars["battery_sn"], request.vars["charger_sn"], request.vars["mac_eth0"], request.vars["mac_wlan0"], request.vars["id_trademark"]) response = l.process("add") if response=="OK": userData = getUserData(request.vars["username"]) max = l.getMaxId() lh = LaptopsHistory(cdb,"",max,"2","2",userData["nif"],request.vars["username"],userData["name"],"") id_laptop = lh.userAssignment() if id_laptop: unassignmentLaptop(id_laptop) lh.add() return dict(response = response)
def base_datos(): import StringIO import os right_version = right_firefox_version(request.env.http_user_agent) if not "archivos" in session.keys(): session.archivos = [] form = SQLFORM.factory(submit_button='Enviar') if form.accepts(request.vars, session): response.flash = 'Procesando datos, espere' #borrando = form.vars.principiocurso if len(session.archivos) > 0: import pdb lista_completa = [] #SQLite=SQLiteConnection() #SQLite.define_tables() #dbcontrolies = SQLite.getDB() #result = db.executesql(sql) for archivo in session.archivos: f = open(archivo) linea = f.readline() last_id = "" while linea: if linea != '\n' and linea != '': linea = linea.split(",") # Datos del portatil serial_number = linea[1].replace("'", "") id_trademark = linea[2] laptop = Laptops(cdb, "", serial_number, id_trademark) if not laptop.existsSerialNumber(laptop.serial_number): laptop.add() last_id = laptop.getIdbySerialNumber( laptop.serial_number) if last_id: # Datos del registro historico id_laptop = last_id username = linea[9].replace("'", "") name = linea[10].replace("'", "") id_user_type = linea[6] nif = linea[5].replace("'", "") id_state = linea[8] laptopshistory = LaptopsHistory( cdb, "", id_laptop, id_state, id_user_type, nif, username, name, "") laptopshistory.add() #dbcontrolies.laptops_historical.insert (**attributes) linea = f.readline() response.flash = T('Ficheros importados correctamente') session.archivos = [] return dict(form=form, right_version=right_version)
def modifySerialNumber(): serialNumber = request.vars["serial_number"].strip() if serialNumber=="": response = "unassignment" else: l = Laptops(cdb,"","","","","","","","") id_laptop = l.existsSerialNumber(serialNumber) response="" if not id_laptop: response = "not_exists" else: lh = LaptopsHistory(cdb,"",id_laptop,"","","","","","") data = lh.getLastHistory() if data["username"]!="" and data["username"]!=request.vars['id']: response = "already_assigned" elif data["username"]!="" and data["username"]==request.vars['id']: response = "OK" else: userData = getUserData(request.vars["id"]) lh = LaptopsHistory(cdb,"",id_laptop,"2","2",userData["nif"],request.vars["id"],userData["name"],"Reasignado") lh.add() response="OK" return dict(response=response)
def modify(): serial = request.vars["serial_number"].strip() l = Laptops(cdb, request.vars["id_laptop"], serial, request.vars["name"], request.vars["battery_sn"], request.vars["charger_sn"], request.vars["mac_eth0"], request.vars["mac_wlan0"], request.vars["id_trademark"]) response = l.process(request.vars["action"]) return dict(response=response)
def reassignmentSerialNumber(): serialNumber = request.vars["serial_number"].strip() newSerialNumber = request.vars["newSerial"].strip() l = Laptops(cdb,"","","","","","","","") if serialNumber!="": id_laptop = l.existsSerialNumber(serialNumber) unassignmentLaptop(id_laptop) if newSerialNumber!="": userData = getUserData(request.vars["username"]) id_laptop = l.existsSerialNumber(newSerialNumber) lh = LaptopsHistory(cdb,"",id_laptop,"2","2",userData["nif"],request.vars["username"],userData["name"],"Reasignado") lh.add() return dict(response="OK")
def delete(): l = Laptops(cdb, request.vars["id_laptop"], "", "", "", "", "", "", "") response = l.delete() return dict(response=response)
def getAllLaptopTypes(): l = Laptops(cdb, "", "", "", "", "", "", "", "") response = l.getAllLaptopTypes() return dict(response=response)
def getLaptopData(): l = Laptops(cdb, request.vars['id_laptop'], "", "", "", "", "", "", "") response = l.getLaptopData() return dict(response=response)
def list(): l = Laptops(cdb, "", "", "", "", "", "", "", "") response = l.list(request.vars) return response