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 search_things_by_location(token, loca_id): # 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_location(loca_id) 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 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)
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)