def create_or_update_unit(): print "Method has been reached " print request.args print request.values print request.stream print request.data print request.method print request.path print request.url print request.is_xhr print request.json unit = simplejson.loads(request.data) print "1" if not unit: abort(400) _dao = dao() print "2" tmpunit = _dao.read_one(unit['id']) print "3" if (tmpunit == None): print "creating" _dao.create_one(unit) else: print "updating" _dao.update_one(unit) print "4" return str(unit), 201
def create_or_update_unit(): print "Method has been reached " print request.args print request.values print request.stream print request.data print request.method print request.path print request.url print request.is_xhr print request.json unit = simplejson.loads(request.data) print "1" if not unit: abort(400) _dao = dao() print "2" tmpunit = _dao.read_one(unit['id']) print "3" if(tmpunit == None): print "creating" _dao.create_one(unit) else: print "updating" _dao.update_one(unit) print "4" return str(unit),201
def TestAddFindChangeDeleteUnit(id): unit = { 'id': id, 'title': 'test case', 'active':True, } tdao = dao() tdao.create_one(unit) #ensure there is atleast one row of data to read, otherwise null on id count = tdao.read_all().count() unit = { 'id': -1, 'title': 'test case', 'active':True } tdao.create_one(unit) if(count+1 != tdao.read_all().count()): print "-Failed to create a unit" return False unit2 = tdao.read_one(unit['id']) if(unit2['title'] == None or unit2['title']=="" or unit2['title'] != unit['title']): print "-failed to read a unit, pulled title is set to " + str(unit2['title']) return False unit['done']= True tdao.update_one(unit) unit2 = tdao.read_one(unit['id']) if(unit2['done']==False): print '-failed to update a unit, value set to true then updated but, result is '+str(unit2['done']) return False #tdao.delete_one(unit['id']) return True
def generar_informe(): try: if request.method == 'POST': consultas = dao() fecha = get_fecha() documento = request.form['documento'] year = request.form['year'] month = request.form['month'] current = [year, get_months()[int(month) - 1]] if year == "": flash('Debe escribir un año') return redirect(url_for('informes_form')) if documento == "": documentos = get_documentos() else: documentos = get_documentos(documento) cur = mysql.connection.cursor() data_info = [] for doc in documentos: cur.execute( consultas.get_consulta_parqueo_carro(year, month, doc[0])) data_carro = list(cur.fetchall()) print(data_carro) data_carro = len(data_carro) cur.execute( consultas.get_consulta_parqueo_moto(year, month, doc[0])) data_moto = list(cur.fetchall()) print(data_moto) data_moto = len(data_moto) cur.execute( consultas.get_consulta_parqueo_bicicleta( year, month, doc[0])) data_bicicleta = list(cur.fetchall()) print(data_bicicleta) data_bicicleta = len(data_bicicleta) cur.execute( consultas.get_consulta_parqueo_total(year, month, doc[0])) data_total = list(cur.fetchall()) data_total = len(data_total) if data_total == 0: continue nombre = "{} {}".format(doc[1], doc[2]) data_info.append([ doc[0], nombre, data_carro, data_moto, data_bicicleta, data_total ]) if len(data_info) == 0: flash('No hay resultados para mostrar') return render_template("informes.html", years=fecha[0], months=fecha[1], data_info=data_info, current=current) except: traceback.print_exc() flash('Error inesperado, sentimos las molestias') return redirect(url_for('defaul'))
def get_unit(unit_id=None): _dao = dao() #unit = [unit for unit in units if unit['id'] == unit_id] if (unit_id == None): return dumps(_dao.read_all()) else: unit = _dao.read_one(unit_id) if (unit == None): return "invalid", 500 else: return dumps(unit) #jsonify({'unit':unit})
def get_unit(unit_id=None): _dao = dao() #unit = [unit for unit in units if unit['id'] == unit_id] if(unit_id==None): return dumps(_dao.read_all()) else: unit = _dao.read_one(unit_id) if (unit == None): return "invalid",500 else: return dumps(unit)#jsonify({'unit':unit})
from dao import * insertInfo = MacInfo('insert', '123', 'test',1) select = MacInfo('select', '123', 'test',1, "SELECT * from ADDRESS_BOOK where MAC = '123'") updateHostname = MacInfo('updateHostname', '123', 'updated hostname',1) updateWatch = MacInfo('updateWatch', '123', 'test',0) delete = MacInfo('delete', '123', 'test',1) dao(insertInfo) dao(select) dao(updateHostname) dao(select) dao(updateWatch) dao(select) dao(delete) dao(select)
def TestConnect(): try: testdao = dao() except: return False return True
import flask from flask import request, jsonify, Flask from flask_cors import CORS, cross_origin from dao import * from beans import * app = flask.Flask(__name__) cors = CORS(app, resources={r'/*': {'origins': '*'}}) app.config['CORS_HEADERS'] = 'Content-Type' app.config['DEBUG'] = True bdd = dao() data = bdd.affJson() @app.route('/', methods=['GET', 'POST']) @cross_origin() def home(): #if request.method == 'GET': # return jsonify(data) if request.method == 'POST': print('response from python flask') newpers = person( request.form.get('cin'), request.form.get('nom'), request.form.get('prenom'), request.form.get('tel'), request.form.get('email'), ) bdd.insertPers(newpers) print(newpers) response = flask.jsonify(bdd.affJson())
from dao import * idNum = 1 _dao = dao() _dao.delete_one(idNum)