def edit_role(id): if request.method == 'POST': try: chk = Role.query.filter("role_name='"+request.form['role_name']+"' and id<>"+str(id)).all() if(chk): # 消息闪现 flash('保存失败,角色名重复','error') return redirect('System/role.page/1') Role.query.filter_by(id=id).update({"role_name":request.form['role_name']}) # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') finally: xmlUtil.updateDynDict('role_all') return redirect('System/role.page/1') elif request.method == 'GET': role = Role.query.filter_by(id=id).first() return render_template("System/role/edit_role.html",role=role)
def new_role(): if request.method == 'POST': try: chk = Role.query.filter_by(role_name=request.form['role_name']).all() if(chk): # 消息闪现 flash('保存失败,角色名重复','error') return redirect('System/role.page/1') # 保存角色 Role(request.form['role_name']).add() # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') finally: xmlUtil.updateDynDict('role_all') return redirect('System/role.page/1') elif request.method == 'GET': return render_template("System/role/new_role.html")
def new_user(pId): if request.method == 'GET': roles = Role.query.order_by("id").all() return render_template("System/user/new_user.html",roles=roles,pId=pId) else: try: chk = User.query.filter_by(login_name=request.form['login_name']).all() if(chk): # 消息闪现 flash('保存失败,登录名重复','error') return redirect('System/user.page/1') level = request.form['level'] if('user' in pId): user = User(request.form['login_name'],GetStringMD5(request.form['login_password']), request.form['real_name'],request.form['sex'],request.form['mobile'],request.form['active'],request.form['email'],request.form['card_id'],level, None,int(pId.split("_")[1])) user.add() else: user = User(request.form['login_name'],GetStringMD5(request.form['login_password']), request.form['real_name'],request.form['sex'],request.form['mobile'],request.form['active'],request.form['email'],request.form['card_id'],level, int(pId.split("_")[1]),None) user.add() #清理缓存 db.session.flush() UserRole(user.id,request.form['roles']).add() # 专家 if level!='3': #专家信息 address = request.form['address'] hy = request.form['hy'] qy = request.form['qy'] product = request.form['product'] balance = request.form['balance'] zyzc = request.form['zyzc'] xrzw = request.form['xrzw'] expert_level = request.form['expert_level'] approve_role = request.form['approve_role'] gzr = request.form['gzr'] gzsd = request.form['gzsd'] Rcs_Expert_Information(user.id,address,hy,qy,product,balance,zyzc,xrzw,expert_level,approve_role,gzr,gzsd).add() # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') finally: xmlUtil.updateDynDict('user_all') return redirect('System/user.page/1')
def delete_role(id): try: UserRole.query.filter_by(role_id=id).delete() Role.query.filter_by(id=id).delete() # 事务提交 db.session.commit() # 消息闪现 flash('删除成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('删除失败','error') finally: xmlUtil.updateDynDict('role_all') return ''
def disable_user(type,id): try: user = User.query.filter_by(id=id).first() user.active = type # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') return helpers.show_result_success('保存成功') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') return helpers.show_result_fail('保存失败') finally: xmlUtil.updateDynDict('user_all')
def edit_org_json(id): try: chk = Org.query.filter("org_name='"+request.form['org_name']+"' and id<>"+str(id)).all() if(chk): # 消息闪现 flash('保存失败,机构名重复','error') return redirect('System/org.page') org = Org.query.filter_by(id=id).first() org.org_name = request.form['org_name'] # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') finally: xmlUtil.updateDynDict('org_all') return redirect('System/org.page')
def new_org_json(pId): try: chk = Org.query.filter_by(org_name=request.form['org_name']).all() if(chk): # 消息闪现 flash('保存失败,机构名重复','error') return redirect('System/org.page') levels = Org.query.filter_by(id=pId).first().levels + 1 Org(request.form['org_name'],pId,levels).add() # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') finally: xmlUtil.updateDynDict('org_all') return redirect('System/org.page')
def edit_user(id): if request.method == 'GET': user = User.query.filter_by(id=id).first() roles = Role.query.order_by("id").all() userrole = UserRole.query.filter_by(user_id=id).first() user_info = Rcs_Expert_Information.query.filter_by(expert_id=id).first() return render_template("System/user/edit_user.html",user=user,roles=roles,userrole=userrole,user_info=user_info) else: try: level = request.form['level'] chk = User.query.filter("login_name='"+request.form['login_name']+"' and id != "+str(id)).all() if(chk): # 消息闪现 flash('保存失败,登录名重复','error') return redirect('System/user.page/1') user = User.query.filter_by(id=id).first() user.login_name = request.form['login_name'] #user.login_password = request.form['login_password'] user.real_name = request.form['real_name'] user.sex = request.form['sex'] user.mobile = request.form['mobile'] user.active = request.form['active'] user.email = request.form['email'] user.modify_user = current_user.id user.modify_date = datetime.datetime.now() if level!='3': user_info = Rcs_Expert_Information.query.filter_by(expert_id=id).first() address = request.form['address'] hy = request.form['hy'] qy = request.form['qy'] product = request.form['product'] balance = request.form['balance'] zyzc = request.form['zyzc'] xrzw = request.form['xrzw'] expert_level = request.form['expert_level'] approve_role = request.form['approve_role'] gzr = request.form['gzr'] gzsd = request.form['gzsd'] if user_info: user_info.address=address user_info.hy=hy user_info.qy=qy user_info.product=product user_info.balance=balance user_info.zyzc=zyzc user_info.xrzw=xrzw user_info.expert_level=expert_level user_info.approve_role=approve_role user_info.gzr=gzr user_info.gzsd=gzsd user_role = UserRole.query.filter_by(user_id=id).first() if user_role: user_role.role_id = request.form['roles'] else: UserRole(id,request.form['roles']).add() # 事务提交 db.session.commit() # 消息闪现 flash('保存成功','success') except: # 回滚 db.session.rollback() logger.exception('exception') # 消息闪现 flash('保存失败','error') finally: xmlUtil.updateDynDict('user_all') return redirect('System/user.page/1')