def run(args, dbparams): id = int(args['id']) import MySQLdb from au_user import getUserId, haveRight, haveProductRight, isUserParent, booltostr, \ getCategoryParent, getProductParent, isCategoryOwner, isProductOwner db=MySQLdb.connect(host=dbparams["host"], db=dbparams["db"], user=dbparams["user"], passwd=dbparams["passwd"]) c=db.cursor() user = getUserId(c, args['name'], args['password']) if args['container'] == 'true': c.execute("SELECT name, oid, mod_servant, mod_others FROM category WHERE id=%s", (id,)) res = c.fetchone() data = {'name': res[0], 'mod_servant': booltostr(res[2]), 'mod_others': booltostr(res[3])} data['owner'] = 'false' data['parmod'] = 'false' data['modify'] = 'false' data['cantake'] = 'false' if user != -1: if isCategoryOwner(c, user, id): data['owner'] = 'true' if haveRight(c, user, id): data['modify'] = 'true' parent = getCategoryParent(c, id) if parent != 0 and haveRight(c, user, parent) and data['modify'] == 'true': data['parmod'] = 'true' if isUserParent(c, res[1], user): data['cantake'] = 'true' else: data['modify'] = 'false' data['parmod'] = 'false' else: c.execute("SELECT name, complex, secret, balt, rieb, angl, descr, linkdescr, " "link, mod_servant, mod_others, oid " "FROM product WHERE id=%s", (id,)) res = c.fetchone() oid = res[11] data = {'name': res[0], 'complex': booltostr(res[1]), 'secret': booltostr(res[2]), 'balt': str(res[3]), 'rieb': str(res[4]), 'angl': str(res[5]), 'descr': res[6], 'linkdescr': res[7], 'link': res[8], 'mod_servant': booltostr(res[9]), 'mod_others': booltostr(res[10]), 'unit_list': []} c.execute("SELECT un.name, u.weight FROM unit u, unitname un WHERE u.prid = %s AND u.unid = un.id", (id,)) res = c.fetchall() for item in res: unit = {'unit': item[0], 'weight': str(item[1])} data['unit_list'].append(unit) data['modify'] = 'false' data['owner'] = 'false' data['parmod'] = 'false' data['cantake'] = 'false' if user != -1: if haveProductRight(c, user, id): data['modify'] = 'true' if isProductOwner(c, user, id): data['owner'] = 'true' parent = getProductParent(c, id) if parent != 0 and haveRight(c, user, parent) and data['modify'] == 'true': data['parmod'] = 'true' if isUserParent(c, oid, user): data['cantake'] = 'true' else: data['modify'] = 'false' data['parmod'] = 'false' c.close() return data
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