def role_add(): data = request.form form = RoleForm(data) if form.validate(): result = Crud.add(Role,data,'name') if result: op_log("添加角色-%s" % data["name"]) return {"code": 1, "msg": '新增成功'} return {"code": 0, "msg": '修改失败,系统错误或名称已存在'} return {"code": 0, "msg": form.get_errors()}
def admin_add_permission(): if request.method == "GET": return render_template('role_add.html') else: forms = RoleForm(request.form) if forms.validate(): datas = forms.data add_common(db, Role, **datas) data = {"msg": "添加成功", "status": "200"} else: data = {"msg": "表单验证失败", "status": "202"} return jsonify(data)
def admin_edit_permission(): if request.method == "GET": ids = request.args.get('id', '') print(ids) if ids or ids != "": tasks = Role.query.filter(Role.id == int(ids)).first() return render_template('role_edit.html', data=tasks) else: tasks = Role.query.filter(Role.id == 1).first() return render_template('role_edit.html', data=tasks) else: forms = RoleForm(request.form) if forms.validate(): datas = forms.data add_common(db, Role, **datas) data = {"msg": "添加成功", "status": "200"} else: data = {"msg": "表单验证失败", "status": "202"} return jsonify(data)
def role_edit(): if request.method == 'GET': getdata = request.args if int(getdata["id"]) == 1: return {"code": 0, "msg": "超级管理员不能修改!"} data = Crud.get_data_by_id(Role, getdata["id"]) # auth_list = list(map(lambda v:int(v),(data.auths).split(","))) auth_list = (data.auths).split(",") role_data = {"name": data.name,"id":data.id, "auths": auth_list} return {"code": 1, "data": role_data} elif request.method == "PUT": data = request.form form = RoleForm(data) if form.validate(): result = Crud.update(Role,data,'name') if result: op_log("修改角色 #%s" % data["id"]) return {"code": 1, "msg": '修改成功'} return {"code": 0, "msg": '修改失败,系统错误或名称已存在'} return {"code": 0, "msg": form.get_errors()}