示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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})
示例#5
0
    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)
示例#6
0
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
示例#7
0
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
示例#8
0
 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)
示例#9
0
 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)