Beispiel #1
0
    def add(self):
        # self.DB.laptops.insert(serial_number=self.serial_number,id_trademark=int(self.id_trademark))
        # self.DB.commit()

        sql = "INSERT INTO laptops (id_laptop,serial_number,name,battery_sn,charger_sn,mac_eth0,mac_wlan0,id_trademark)"
        sql = (
            sql
            + " VALUES (null,'"
            + self.serial_number
            + "','"
            + self.name
            + "','"
            + self.battery_sn
            + "','"
            + self.charger_sn
            + "','"
            + self.mac_eth0
            + "','"
            + self.mac_wlan0
            + "',"
            + self.id_trademark
            + ")"
        )
        result = self.DB.executesql(sql)

        max = self.getMaxId()
        lh = LaptopsHistory(self.DB, "", max, "1", "0", "", "", "", "Nuevo en el sistema")
        lh.add()

        return "OK"
Beispiel #2
0
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)
Beispiel #3
0
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)  
Beispiel #4
0
def getAllStatesGrid():
    l = LaptopsHistory(cdb, "", "", "", "", "", "", "", "")
    r = l.getAllStates()

    text = ""
    for i in r:
        text += i["id_state"] + ":" + i["state"] + ";"
    text = "2:hola"
    return text  #{"States":{"Content":text}}
Beispiel #5
0
def getAllStatesGrid():
    l = LaptopsHistory(cdb,"","","","","","","","")
    r = l.getAllStates()
    
    text=""
    for i in r:
        text+= i["id_state"]+":"+i["state"]+";"
    text = "2:hola"
    return text #{"States":{"Content":text}}
Beispiel #6
0
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)
Beispiel #7
0
def modifyHistory():
    l = LaptopsHistory(cdb, request.vars["id_historical"],
                       request.vars["id_laptop"], request.vars["id_state"],
                       request.vars["id_user_type"],
                       request.vars["nif"].strip(),
                       request.vars["username"].strip(),
                       request.vars["name"].strip(), request.vars["comment"],
                       request.vars["computer_name"])
    response = l.process(request.vars["action"])
    return dict(response=response)
Beispiel #8
0
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")   
Beispiel #9
0
def modifyHistory():
    l = LaptopsHistory(
        cdb,
        request.vars["id_historical"],
        request.vars["id_laptop"],
        request.vars["id_state"],
        request.vars["id_user_type"],
        request.vars["nif"].strip(),
        request.vars["username"].strip(),
        request.vars["name"].strip(),
        request.vars["comment"],
    )
    response = l.process(request.vars["action"])
    return dict(response=response)
Beispiel #10
0
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)
Beispiel #11
0
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") 
Beispiel #12
0
def getAllUserTypes():
    l = LaptopsHistory(cdb, "", "", "", "", "", "", "", "", "")
    response = l.getAllUserTypes()
    return dict(response=response)
Beispiel #13
0
def addHistory(l,username,id_laptop,computer_name):
    
    lh = LaptopsHistory(cdb,"",id_laptop,"","","","","","","")
    lastUsername = lh.getLastHistory()

    if username!="" and lastUsername['username']!=username:
        u = Users(l,"","","","",username,"","","","")
        userData = u.getUserData()
        
        if userData["uidnumber"]!="": # Si existe el usuario
            lh.set_id_state(2) # Asignado
            
            if userData["type"]=="student":
                lh.set_id_user_type(2)
            elif userData["type"]=="teacher":
                lh.set_id_user_type(1)

            lh.set_computer_name(computer_name)    
            lh.set_username(username)
            lh.set_name(userData["name"]+" "+userData["surname"])
            lh.set_nif(userData["nif"])
            lh.set_comment("Volcado masivo ControlIES")
            lh.add()
    
    elif username=="" and lastUsername['username']!="":
        lh.set_id_state(1) # No Asignado
        lh.set_computer_name(computer_name)        
        lh.set_comment("Volcado masivo ControlIES")
        lh.add()
Beispiel #14
0
def getDataHistory():
    l = LaptopsHistory(cdb, request.vars["id_historical"], "", "", "", "", "",
                       "", "", "")
    response = l.getDataHistory()
    return dict(response=response)
Beispiel #15
0
def getAllStates():
    l = LaptopsHistory(cdb,"","","","","","","","","")
    response = l.getAllStates()
    return dict(response=response)
Beispiel #16
0
def deleteHistory():
    l = LaptopsHistory(cdb,request.vars["id_historical"],"","","","","","","","")
    response = l.delete()                         
    return dict(response=response)
Beispiel #17
0
def listHistory():    
    l = LaptopsHistory(cdb,"",request.vars["id_laptop"],"","","","","","","")
    response = l.list(request.vars)
    return response
Beispiel #18
0
def getDataLastHistory():
    l = LaptopsHistory(cdb, "", request.vars["id_laptop"], "", "", "", "", "",
                       "", "")
    response = l.getLastHistory()
    return dict(response=response)
Beispiel #19
0
def getDataLastHistory():
    l = LaptopsHistory(cdb,"",request.vars["id_laptop"],"","","","","","","")
    response = l.getLastHistory()
    return dict(response=response)
Beispiel #20
0
def getDataHistory():
    l = LaptopsHistory(cdb,request.vars["id_historical"],"","","","","","","","")
    response = l.getDataHistory()
    return dict(response=response)
Beispiel #21
0
def listHistory():
    l = LaptopsHistory(cdb, "", request.vars["id_laptop"], "", "", "", "", "",
                       "", "")
    response = l.list(request.vars)
    return response
Beispiel #22
0
def deleteHistory():
    l = LaptopsHistory(cdb, request.vars["id_historical"], "", "", "", "", "",
                       "", "", "")
    response = l.delete()
    return dict(response=response)
Beispiel #23
0
def unassignmentLaptop(id_laptop):
    unassignment = LaptopsHistory(cdb,"",id_laptop,"1","","","","","Desasignado")
    unassignment.add()