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 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()}