コード例 #1
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def findThing():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    numThing = request.form['numeroPat']
    location = Locations()
    locations = location.search_all_locations()

    things = Things()
    try:
        response = things.search_things_by_num1(numThing)

        if response == False:
            return render_template('/things.html',
                                   message="No thing found with given number",
                                   alertlevel="warning")
        else:
            return render_template('/things.html',
                                   thing=response,
                                   locations=locations)
    except Exception as e:
        return render_template(
            '/things.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
コード例 #2
0
def thingsTableWriter():
    things = Things()
    location = things.search_locations()

    code = request.form['code1']
    loca_id = request.form['location2']

    if loca_id != "0" and code == "":
        dados = things.search_things_inactives_by_location(loca_id)

        if dados == False:
            msg = "Objects not found."
            return render_template('/writer.html',
                                   locations=location,
                                   message=msg)

    elif loca_id == "0" and code != "":
        dados = []
        dados.append(things.search_things_by_num1(code))

        if dados[0] == False:
            msg = "Objects not found."
            return render_template('/writer.html',
                                   locations=location,
                                   message=msg)
    else:
        msg = "Please, Enter a Code or Location to Write."
        return render_template('/writer.html', locations=location, message=msg)

    return render_template('/writer.html', locations=location, dado=dados)
コード例 #3
0
    def synchronize_location(self, nr_things1, location, user):
        thingsXLocation = ThingsXLocation()
        things = Things()

        thingsExists = things.search_things_by_num1(nr_things1)
        if thingsExists != False:
            pabe_id = thingsExists.code_things
            exists = thingsXLocation.check_thing_location_exists(nr_things1)

            if exists == True:
                update = thingsXLocation.update_thing_location(
                    pabe_id, location, user)
                if update:
                    return True
                else:
                    return 'Ocorreu um erro ao atualizar a localização da coisa'
            elif exists == False:
                insert = thingsXLocation.insert_patr_bens_x_localizacao(
                    pabe_id, location, user)
                if insert:
                    return True
                else:
                    return 'Ocorreu um erro ao inserir a localização da coisa'
            else:
                return 'Ocorreu um erro ao verificar a localização atual da coisa'
        elif thingsExists == False:
            return 'Codigo da coisa inexistente'
        else:
            return 'Ocorreu um erro ao verificar se a coisa existe'
コード例 #4
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def thingsgrid():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    acao = request.args.get("acao")
    message = ''
    things = Things()
    thingsXLocation = ThingsXLocation()
    response = things.search_all_things()
    if acao == "search":
        tipo_busca = request.args.get("tipo_busca")
        dado = request.args.get("dado_busca")
        print(tipo_busca)
        if tipo_busca != '-1':
            if tipo_busca == '4':
                response = []
                dado2 = request.args.get("dado_busca2")
                resp = things.search_things_by_num1(dado2)
                if resp == False:
                    message = "No thing found!"
                elif resp == 'ERRO':
                    message = 'Ocorreu um erro no servidor'
                else:
                    response.append(resp)
            elif dado != '-1':
                if tipo_busca == '1':
                    response = things.search_things_by_location(dado)

                elif tipo_busca == '2':
                    response = thingsXLocation.search_things_over_by_location(
                        dado)
                elif tipo_busca == '3':
                    response = thingsXLocation.search_things_missing_by_location(
                        dado)
    if response == False:
        response = []
        message = "No thing found!"
    if response == 'ERRO':
        response = []
        message = "Error while searching"
    location = Locations()
    locations = location.search_all_locations()

    if message != '':
        return render_template('/thingsgrid.html',
                               things=response,
                               locations=locations,
                               message=message,
                               alertlevel="warning")
    else:
        return render_template('/thingsgrid.html',
                               things=response,
                               locations=locations)
コード例 #5
0
def findThing():
    numThing = request.form['numeroPat']

    things = Things()
    try:
        response = things.search_things_by_num1(numThing)

        if response == False:
            return "Nenhuma coisa encontrada com o número informado"
        else:
            return render_template('/things.html', thing=response)
    except Exception as e:
        return 'Erro no servidor. Contate o analista responsável!'
コード例 #6
0
def thingsTableReader():
    things = Things()
    location = things.search_locations()

    loca_id = request.form['location1']

    if loca_id != "0":
        #chama metodo de leitura
        print("Inserir função de leitura")
        txt = "Waiting for Reading ..."
    else:
        msg = "Please, Select a Location to Read."
        return render_template('/reader.html', locations=location, message=msg)

    return render_template('/reader.html', locations=location, texto=txt)
コード例 #7
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def search_all_things_actives(token):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    things = Things()
    response = things.search_all_things_actives()
    if response == False:
        return jsonify({'response': 'Nenhum objeto encontrado'})
    elif response == 'ERRO':
        return jsonify({'response': 'Ocorreu um erro no servidor'})
    else:
        return json.dumps(para_dict(response))
コード例 #8
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def deleteLocation():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    locaId = request.form['locationId']
    things = Things()
    locationsBD = Locations()
    try:
        locations = locationsBD.search_all_locations()
        response = things.search_things_by_location(locaId)
        if response == False:
            response = locationsBD.delete_location(locaId)
            locations = locationsBD.search_all_locations()
            if response == True:
                return render_template('/locationsgrid.html',
                                       message="Location deleted sucessfully",
                                       alertlevel="success",
                                       locations=locations)
            else:
                return render_template(
                    '/locationsgrid.html',
                    message=
                    "A database error has occurred. Contact your system administrator",
                    alertlevel="danger",
                    locations=locations)
        else:
            return render_template(
                '/locationsgrid.html',
                message=
                "You can't delete locations with things associated with",
                alertlevel="warning",
                locations=locations)
    except Exception as e:
        print(e)
        return render_template(
            '/locationsgrid.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger",
            locations=locations)
コード例 #9
0
    def synchronize_things(self, nr_things1, situation, state, note, user,
                           current_location, location):
        things = Things()
        thingsXLocation = ThingsXLocation()

        thingsExists = things.search_things_by_num1(nr_things1)
        if thingsExists != False:
            pabe_id = thingsExists.code_things
            update = things.update_thing(pabe_id, situation, state, note,
                                         location)
            if update == False:
                return 'Ocorreu um erro ao atualizar o objeto'

            if current_location != None and current_location != "0":
                exists = thingsXLocation.check_thing_location_exists(
                    nr_things1)
                if exists == True:
                    current_location_db = thingsXLocation.get_location_current(
                        pabe_id)
                    if current_location != False and current_location != 'ERRO':
                        if current_location_db != current_location:
                            update = thingsXLocation.update_thing_location(
                                pabe_id, current_location, user)
                            if update:
                                return True
                            else:
                                return 'Ocorreu um erro ao atualizar a localização da coisa'

                elif exists == False:
                    insert = thingsXLocation.insert_patr_bens_x_localizacao(
                        pabe_id, current_location, user)
                    if insert:
                        return True
                    else:
                        return 'Ocorreu um erro ao inserir a localização da coisa'
                else:
                    return 'Ocorreu um erro ao verificar a localização atual da coisa'
            return True
        elif thingsExists == False:
            return 'Codigo da coisa inexistente'
        else:
            return 'Ocorreu um erro ao verificar se a coisa existe'
コード例 #10
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def active_thing_by_num(token, num):
    # valida token
    user = User()
    resp = user.verify_token(token)
    if resp == False:
        return jsonify({'response': 'Token Invalido'})
    elif resp == 'ERRO':
        return jsonify({'response': 'Erro ao verificar token'})

    things = Things()
    exits = things.search_things_by_num1(num)
    if exits:
        response = things.active_things_by_num1(num)
        if response == False:
            return jsonify(
                {'response': 'Ocorreu um erro ao ativar a etiqueta'})
        else:
            return jsonify({'response': 'true'})
    else:
        return jsonify({'response': 'Objeto não encontrado'})
コード例 #11
0
def addthing():
    descricao = request.form['descricao']
    num1 = request.form['num1']
    num2 = request.form['num2']
    preco = request.form['preco']
    situacao = request.form['situacao']
    estado = request.form['estado']
    observacao = request.form['observacao']

    thing = Things()
    try:
        response = thing.insert_new_thing(num1, num2, descricao, preco,
                                          situacao, estado, observacao)
        if response == True:
            return "Coisa cadastrada com sucesso."
        else:
            return "Erro ao cadastrar coisa."

    except Exception as e:
        return 'Erro no servidor. Contate o analista responsável !!'
コード例 #12
0
def editThing():
    id = request.form['id']
    descricao = request.form['descricao']
    num1 = request.form['num1']
    num2 = request.form['num2']
    preco = request.form['preco']
    situacao = request.form['situacao']
    estado = request.form['estado']
    observacao = request.form['observacao']

    thing = Things()

    try:
        response = thing.update_thing2(id, descricao, num1, num2, preco,
                                       situacao, estado, observacao)
        if response == True:
            return "Coisa atualizada com sucesso"
        else:
            return "Erro ao atualizar coisa"
    except Exception as e:
        return 'Erro no servidor. Contate o analista responsável!'
コード例 #13
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def editThing():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    id = request.form['id']
    descricao = request.form['descricao']
    num1 = request.form['num1']
    num2 = request.form['num2']
    localizacao = request.form['location']
    preco = request.form['preco']
    situacao = request.form['situacao']
    estado = request.form['estado']
    observacao = request.form['observacao']
    thingmodel = ThingsModel(id, num1, num2, descricao, situacao, preco,
                             estado, localizacao, observacao)
    thing = Things()
    location = Locations()
    locations = location.search_all_locations()

    try:
        response = thing.update_thing2(id, descricao, num1, num2, localizacao,
                                       preco, situacao, estado, observacao)
        if response == True:
            return render_template('/things.html',
                                   message="Thing successfully edited",
                                   alertlevel="success",
                                   thing=thingmodel,
                                   locations=locations)
        else:
            return render_template('/things.html',
                                   message="Error while editing thing",
                                   alertlevel="warning")
    except Exception as e:
        return render_template(
            '/things.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
コード例 #14
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def addthing():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    descricao = request.form['descricao']
    num1 = request.form['num1']
    num2 = request.form['num2']
    localizacao = request.form['location']
    preco = request.form['preco']
    situacao = request.form['situacao']
    estado = request.form['estado']
    observacao = request.form['observacao']

    thing = Things()
    try:
        response = thing.insert_new_thing(num1, num2, descricao, localizacao,
                                          preco, situacao, estado, observacao)
        if response == True:
            return render_template('/things.html',
                                   message="Thing successfully added",
                                   alertlevel="success")
        elif response == '1062':
            return render_template(
                '/things.html',
                message="There's a thing registered with the given number",
                alertlevel="danger")
        else:
            return render_template('/things.html',
                                   message="Error",
                                   alertlevel="danger")
    except Exception as e:
        return render_template(
            '/things.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
コード例 #15
0
def thingsTable():
    things = Things()
    location = things.search_locations()

    loca_id = request.form['location']
    status = request.form['status']

    if loca_id == "0" and status == "1":
        thingsdata = things.search_all_things_actives()

        if thingsdata == False:
            msg = "Object not found."
            return render_template('/things.html',
                                   location=location,
                                   message=msg)

    elif loca_id == "0" and status == "2":
        thingsdata = things.search_all_things_inactives()

        if thingsdata == False:
            msg = "Object not found."
            return render_template('/things.html',
                                   location=location,
                                   message=msg)

    elif loca_id != "0" and status == "0":
        thingsdata = things.search_things_by_location(loca_id)

        if thingsdata == False:
            msg = "Object not found."
            return render_template('/things.html',
                                   location=location,
                                   message=msg)

    elif loca_id != "0" and status == "1":
        thingsdata = things.search_things_actives_by_location(loca_id)

        if thingsdata == False:
            msg = "Object not found."
            return render_template('/things.html',
                                   location=location,
                                   message=msg)

    elif loca_id != "0" and status == "2":
        thingsdata = things.search_things_inactives_by_location(loca_id)

        if thingsdata == False:
            msg = "Object not found."
            return render_template('/things.html',
                                   location=location,
                                   message=msg)

    elif loca_id == "0" and status == "0":
        msg = "Please select a Location or Status for consultation. Or, if you prefer, select both."
        return render_template('/things.html', location=location, message=msg)

    # thingsData = things.search_things_by_location (loca_id)

    return render_template('/things.html',
                           thingsdata=thingsdata,
                           location=location)
コード例 #16
0
def listLocationWriter():
    things = Things()
    location = things.search_locations()

    return render_template('/writer.html', locations=location)
コード例 #17
0
ファイル: api02.py プロジェクト: enanlara/2TsServer
def get_things_db(token):
    if token != token_padrao_get_db:
        return jsonify({'response': 'Token Invalido'})

    things = Things()
    return things.generate_sql_insert_things()
コード例 #18
0
def locations():
    things = Things()
    location = things.search_locations()

    return render_template('/things.html', location=location)