def run(args, dbparams): try: amount = float(args["amount"]) except ValueError: amount = 0.0 from au_user import getUserId, haveProductRight import MySQLdb db = MySQLdb.connect(host=dbparams["host"], db=dbparams["db"], user=dbparams["user"], passwd=dbparams["passwd"]) db.autocommit(False) c = db.cursor() user = getUserId(c, args["user"], args["password"]) if user == -1: data = {"pass": "******"} c.close() return data if haveProductRight(c, user, int(args["id"])): c.execute("SELECT id FROM unitname WHERE name=%s", (args["unit"],)) res = c.fetchone() unid = res[0] c.execute("SELECT id FROM unit WHERE unid=%s AND prid=%s", (unid, int(args["prid"]))) res = c.fetchone() uid = res[0] c.execute("SELECT id FROM unitname WHERE name=%s", (args["oldunit"],)) res = c.fetchone() unid = res[0] c.execute("SELECT id FROM unit WHERE unid=%s AND prid=%s", (unid, int(args["prid"]))) res = c.fetchone() old_uid = res[0] c.execute( "UPDATE complex SET uid=%s, amount=%s WHERE prid=%s AND uid=%s", (uid, amount, int(args["id"]), old_uid) ) data = {"pass": "******"} from au_calcBAR import calcBAR, updateComplex elem = calcBAR(c, int(args["id"])) updateComplex(c, int(args["id"])) db.commit() data["balt"] = elem[0] data["angl"] = elem[1] data["rieb"] = elem[2] data["total"] = elem[3] else: data = {"pass": "******"} c.close() return data
def run(args, dbparams): from au_user import getUserId, haveProductRight import MySQLdb db=MySQLdb.connect(host=dbparams["host"], db=dbparams["db"], user=dbparams["user"], passwd=dbparams["passwd"]) db.autocommit(False) c=db.cursor() user = getUserId(c, args['user'], args['password']) data = {} if user == -1: data['pass'] = '******' c.close() return data if haveProductRight(c, user, int(args['id'])) and noCircularDep(c, int(args['id']), int(args['prid'])): c.execute("SELECT count(*) FROM unit u, complex c " "WHERE c.prid = %s AND c.uid = u.id AND u.prid = %s", (int(args['id']), int(args['prid']))) count = c.fetchone()[0]; if count == 0: data['pass'] = '******' data['list'] = [] c.execute("SELECT un.name, u.id FROM unit u, unitname un WHERE u.prid = %s AND u.unid = un.id", (int(args['prid']),)) units = c.fetchall() for u in units: data['list'].append({'name': u[0]}) c.execute("INSERT INTO complex(prid, uid, amount) VALUES (%s, %s, %s)", (int(args['id']), units[0][1], '0.0')) from au_calcBAR import calcBAR, updateComplex elem = calcBAR(c, int(args['id'])) updateComplex(c, int(args['id'])) db.commit() data['balt'] = elem[0] data['angl'] = elem[1] data['rieb'] = elem[2] data['total'] = elem[3] else: data['pass'] = '******' else: data['pass'] = '******' c.close() return data
def run(args, dbparams): from au_user import getUserId, haveProductRight import MySQLdb db=MySQLdb.connect(host=dbparams["host"], db=dbparams["db"], user=dbparams["user"], passwd=dbparams["passwd"]) db.autocommit(False) c=db.cursor() user = getUserId(c, args['user'], args['password']) if user == -1: data = {'pass': '******'} c.close() return data if haveProductRight(c, user, int(args['id'])): c.execute("SELECT id FROM unitname WHERE name=%s", (args['unit'],)) res = c.fetchone() unid = res[0] c.execute("SELECT id FROM unit WHERE unid=%s AND prid=%s", (unid, int(args['prid']))) res = c.fetchone() uid = res[0] c.execute("DELETE FROM complex WHERE prid=%s AND uid=%s", (int(args['id']), uid)) data = {'pass': '******'} from au_calcBAR import calcBAR, updateComplex elem = calcBAR(c, int(args['id'])) updateComplex(c, int(args['id'])) db.commit() data['balt'] = elem[0] data['angl'] = elem[1] data['rieb'] = elem[2] data['total'] = elem[3] else: data = {'pass': '******'} c.close() return data