コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
def run(args, dbparams):
    try:
        balt = float(args['balt'])
    except ValueError:
        balt = 0.0
    try:
        rieb = float(args['rieb'])
    except ValueError:
        rieb = 0.0
    try:
        angl = float(args['angl'])
    except ValueError:
        angl = 0.0

    import MySQLdb
    from au_user import getUserId, haveProductRight, isProductOwner
    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'])):
        complex = 0
        if args['complex'] == 'true':
            complex = 1

        secret = 0
        if args['secret'] == 'true':
            secret = 1

        c.execute("UPDATE product SET name=%s, balt=%s, rieb=%s, angl=%s, complex=%s, descr=%s, "
                  "secret=%s, linkdescr=%s, link=%s "
                  "WHERE id=%s",
                  (args['name'], balt, rieb, angl,
                   complex, args['descr'],
                   secret, args['linkdescr'], args['link'],
                   int(args['id'])))
        from au_calcBAR import updateComplex
        updateComplex(c, int(args['id']))
    else:
        data = {'pass': '******'}
        c.close()
        return data

    if isProductOwner(c, user, int(args['id'])):
        mod_servant = 0
        if args['mod_servant'] == 'true':
            mod_servant = 1
        mod_others = 0
        if args['mod_others'] == 'true':
            mod_others = 1
        c.execute("UPDATE product SET mod_servant=%s, mod_others=%s WHERE id=%s",
                  (mod_servant, mod_others, int(args['id'])))

    db.commit()
    data = {'pass': '******'}

    c.close()
    return data