def get(self, _id): sql = "select * from t_workflows where id = {}".format(_id) rs = QS.query(dbconf('userruledb'), sql) or [] if len(rs) == 0: return json_error(404) sql = "select id, workflowid, criterias, action, reviewid, decisionid from t_routes where workflowid = {} ".format( _id) rs = QS.query(dbconf('userruledb'), sql) or [] return json_error(200, data=rs)
def delete(self, _id): sql = "select id from t_routes where id = {}".format(_id) rs = QS.query(dbconf('userruledb'), sql) or [] if len(rs) == 0: return json_error(404) json = request.json sql = "delete from t_routes where id = {}".format(_id) QS.query(dbconf('userruledb'), sql) return json_error(200)
def put(self, _id): json = request.json sql = "select id from t_workflows where id = {}".format(_id) rs = QS.query(dbconf('userruledb'), sql) or [] if len(rs) == 0: return json_error(404) updatesql = get_update_sql_by_json('t_workflows', json, _id) rs = QS.query(dbconf('userruledb'), updatesql) print 'rs:', rs return json_error(200)
def post(self): cnx = get_cnx('userruledb') json = request.json response_id = 0 workflowid = json['workflowid'] rs = QS.query( dbconf('userruledb'), 'select * from t_workflows where id = {}'.format(workflowid), True) or [] if len(rs) == 0: return json_error(404) sql = u"insert into t_routes set workflowid='{}', criterias='{}', action='{}', reviewid='{}', decisionid='{}'".format( workflowid, json['criterias'] if json.has_key('criterias') else '', '2', '0', json['decisionid'] if json.has_key('decisionid') else '0') with cnx.cursor() as cur: cur.execute(sql) cnx.commit() print "ID of inserted record is ", int(cur.lastrowid) response_id = cur.lastrowid # if len(rs['routes']) == 0: # routesstr = str(response_id) # else: # routeslist = rs['routes'].split(',') # routeslist.append(str(response_id)) # routesstr = ','.join(routeslist) # updatesql = 'update t_workflows set routes = "{}" where id = {}'.format(routesstr, workflowid) # QS.query(dbconf('userruledb'), updatesql) return json_error(201, data={'id': response_id})
def get(self, _id): cnx = get_cnx('userruledb') sql = ' select id, name, event, affecting, status from t_workflows where id = {}'.format( _id) rs = QS.query(dbconf('userruledb'), sql) or [] if len(rs) == 0: return json_error(404) return json_error(200, data=rs)
def get_rds(): attr = 'rds' cnx = getattr(g, attr, None) if cnx is None: cnf = dbconf(attr) _cnx = redis.Redis(**cnf) setattr(g, attr, _cnx) return _cnx return cnx
def get_cnx(nm): attr = 'cnx_%s' % nm cnx = getattr(g, attr, None) if (cnx is None): cnf = dbconf(nm) # TBD: dbconf cnf["cursorclass"] = pymysql.cursors.Cursor _cnx = pymysql.connect(**cnf) setattr(g, attr, _cnx) return _cnx return cnx
def get(self): cnx = get_cnx('userruledb') sql = ' select id, name, event, affecting, status from t_workflows' rs = QS.query(dbconf('userruledb'), sql) or [] return json_error(200, data=rs)
def get(self): cnx = get_cnx('userruledb') sql = ' select id, workflowid, criterias, action, reviewid, decisionid from t_routes' rs = QS.query(dbconf('userruledb'), sql) or [] return json_error(200, data=rs)