예제 #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
파일: api02.py 프로젝트: enanlara/2TsServer
def addlocation():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    locationBD = Locations()
    locaNome = request.form['name']
    try:
        response = locationBD.insert_location(locaNome)
        locations = locationBD.search_all_locations()
        if response == True:
            return render_template('/locations.html',
                                   message="Location added successfully",
                                   alertlevel="success",
                                   locations=locations)
        else:
            return render_template('/locations.html',
                                   message="Error adding location",
                                   alertlevel="danger",
                                   locations=locations)

    except Exception as e:
        return render_template(
            '/locations.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger",
            locations=locations)
예제 #3
0
파일: api02.py 프로젝트: enanlara/2TsServer
def editlocation():
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    location = Locations()
    locations = location.search_all_locations()
    nome = request.form['name']
    id = request.form['id']
    try:
        response = location.edit_location(id, nome)
        if response == False:
            return render_template('/locations.html',
                                   message="Error updating location",
                                   alertlevel="danger",
                                   locations=locations)
        else:
            return render_template('/locations.html',
                                   message="Location updated",
                                   alertlevel="success",
                                   locations=locations)

    except Exception as e:
        return render_template(
            '/locations.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
예제 #4
0
파일: api02.py 프로젝트: enanlara/2TsServer
def findlocation():
    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['locationId']
    location = Locations()
    locations = location.search_all_locations()
    try:
        response = location.search_location_by_id(id)
        if response == False:
            return render_template('/locations.html',
                                   message="Error finding locations",
                                   alertlevel="danger")
        else:
            return render_template('/locations.html',
                                   locations=locations,
                                   location=response)

    except Exception as e:
        return render_template(
            '/locations.html',
            message=
            "A database error has occurred. Contact your system administrator",
            alertlevel="danger")
예제 #5
0
파일: api02.py 프로젝트: enanlara/2TsServer
def locationsgrid():
    locations = Locations()
    locations = locations.search_all_locations()
    if session.get('token') is None:
        return render_template(
            '/login.html',
            message="You have to login to access this module",
            alertlevel="warning")
    return render_template('/locationsgrid.html', locations=locations)
예제 #6
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)
예제 #7
0
파일: api02.py 프로젝트: enanlara/2TsServer
def search_locations(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'})

    location = Locations()
    response = location.search_all_locations()
    if response == False:
        return jsonify({'response': 'Nenhuma localizacao encontrada'})
    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
파일: 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")
예제 #10
0
파일: api02.py 프로젝트: enanlara/2TsServer
def get_locations_db(token):
    if token != token_padrao_get_db:
        return jsonify({'response': 'Token Invalido'})

    location = Locations()
    return location.generate_sql_insert_locations()