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")
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'
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)
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)
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!'
def search_things_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() response = things.search_things_by_num1(num) 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))
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'
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'})