def add_permission_lib(self, name, strcode): """04添加权限""" permission = Permission.by_name(name) if permission is not None: return permission = Permission() permission.name = name permission.strcode = strcode self.db.add(permission) self.db.commit()
def add_permission_lib(self, name, strcode): """04添加权限""" permission= Permission.by_name(name) if permission is not None: flash(self, "权限已存在,添加失败", "error") return permission = Permission() permission.name = name permission.strcode = strcode self.db.add(permission) self.db.commit() flash(self, "权限添加成功", "success")
def permission_add_code(self, permission_name, permission_code): ''' 添加权限名和权限码 ''' if permission_name == '': return {'status': False, 'msg': '请输入权限名'} if permission_code == '': return {'status': False, 'msg': '请输入权限码'} permission = Permission() permission.name = permission_name permission.strcode = permission_code self.db.add(permission) self.db.commit() return {'status': True, 'msg': '添加成功'}
def add_permission_lib(self, name, strcode): '''04添加权限''' if not name or not strcode: flash(self, '请输入权限名和权限码!', 'error') return permission = Permission.by_name(name) # 如果权限有,就不用添加 if permission is not None: flash(self, '权限已存在!', 'error') return permission = Permission() permission.name = name permission.strcode = strcode self.db.add(permission) self.db.commit() flash(self, '权限添加成功!', 'success')
def del_permission_lib(self, permissionid): """05删除权限函数""" permission = Permission.by_id(permissionid) if permission is None: return self.db.delete(permission) self.db.commit()
def permission_manager_list_lib(self): ''' 返回给权限管理页面 ''' roles = Role.all() permissions = Permission.all() menus = Menu.all() handlers = Handler.all() users = User.all() return roles, permissions, menus, handlers, users
def permission_del_code(self, permission_id): ''' 删除权限名和权限码 ''' permission = Permission.by_id(permission_id) if permission: self.db.delete(permission) self.db.commit() return {'status': True} return {'status': False, 'msg': '不存在的ID'}
def permission_manager_list_lib(self): # 获取所有的角色/权限/菜单/处理器/用户 roles = Role.all() permissions = Permission.all() menus = Menu.all() handlers = Handler.all() users = User.all() return roles, permissions, menus, handlers, users
def del_permission_lib(self,perid): """05删除权限函数""" per = Permission.by_id(perid) if per is None: flash(self, "此权限不存在,删除失败", "error") return self.db.delete(per) self.db.commit() flash(self, "权限删除成功", "success")
def add_permission_role_lib(self, permissionid , roleid): """11为角色添加权限""" permission = Permission.by_id(permissionid) role = Role.by_id(roleid) if permission is None or role is None: return role.permissions.append(permission) self.db.add(role) self.db.commit()
def add_role_permission_lib(self, permissionid, roleid): permission = Permission.by_id(permissionid) role = Role.by_id(roleid) if permission is None or role is None: return permission.roles.append(role) #多对多关系添加 self.db.add(permission) self.db.commit()
def del_permission_lib(self, permissionid): """05删除权限""" permission = Permission.by_id(permissionid) if permission is None: return self.db.delete(permission) self.db.commit() flash(self, "权限删除成功", "success")
def add_role_permission_lib(self, roleid, permissionid): """11为角色添加权限""" role = Role.by_id(roleid) permission = Permission.by_id(permissionid) if role is None or permission is None: return role.permissions.append(permission) self.db.add(role) self.db.commit() flash(self, "为角色添加权限添加成功", "success")
def del_permission_lib(self, permissionid): '''05删除权限''' permission = Permission.by_id(permissionid) # 判断该权限id获取值是否为空 if permission is None: flash(self, '权限不存在,删除失败!', 'error') return self.db.delete(permission) self.db.commit() flash(self, '权限删除成功!', 'success')
def add_role_permission_lib(self, permissionid, roleid): """11为角色添加权限""" permission = Permission.by_id(permissionid) role = Role.by_id(roleid) if permission is None or role is None: flash(self, "为角色添加权限失败", "error") return permission.roles.append(role) #多对多关系添加 self.db.add(permission) self.db.commit() flash(self, "为角色添加权限成功", "success")
def add_handler_lib(self, name, permissionid): """08为视图添加权限函数""" permission = Permission.by_id(permissionid) handler = Handler.by_name(name) if permission is None: return if handler is None: handler = Handler() handler.name =name handler.permission = permission self.db.add(handler) self.db.commit()
def add_menu_lib(self,name, permissionid): """06为菜单添加权限函数""" permission = Permission.by_id(permissionid) menu = Menu.by_name(name) if permission is None: return if menu is None: menu = Menu() menu.name =name menu.permission = permission self.db.add(menu) self.db.commit()
def permission_manager_list_lib(self): """01权限管理页面函数""" roles = Role.all() permissions = Permission.all() menus = Menu.all() handlers = Handler.all() users = User.all() #研发员工 dev_role = Role.by_name('研发员工') dev_users = dev_role.users if dev_role else [] return roles, permissions, menus, handlers, users, dev_users, dev_role.id
def add_handler_lib(self, name, permissionid): permission = Permission.by_id(permissionid) if permission is None: return hanlder = Handler.by_name(name) # 注意 if hanlder is None: hanlder = Handler() hanlder.name = name hanlder.permission = permission # 问题 可不可以 self.db.add(hanlder) self.db.commit()
def add_handler_lib(self, name, permissionid): """08为视图添加权限函数""" permission = Permission.by_id(permissionid) if permission is None: flash(self, "处理器权限,添加失败", "error") return hanlder = Handler.by_name(name) # 注意 if hanlder is None: hanlder = Handler() hanlder.name = name hanlder.permission = permission self.db.add(hanlder) self.db.commit() flash(self, "处理器权限,添加成功", "success")
def add_menu_lib(self, name, permissionid): permission = Permission.by_id(permissionid) if permission is None: return menu = Menu.by_name(name) #注意 if menu is None: menu = Menu() menu.name = name menu.permission = permission #问题 可不可以 #menu.p_id = permissionid self.db.add(menu) self.db.commit()
def add_role_permission_lib(self, roleid, permissionid): '''11 给角色添加权限''' if not permissionid or not roleid: flash(self, '请输入角色id!和权限id!', 'error') return permission = Permission.by_id(permissionid) role = Role.by_id(roleid) if permission is None or role is None: flash(self, '角色id或权限id不存在!', 'error') return permission.roles.append(role) # 多对多关系添加,数组添加 print 'permission%s' % permission self.db.add(permission) self.db.commit() flash(self, '给角色添加权限成功!', 'success')
def add_handler_lib(self, name, permissionid): """08为处理器添加权限""" permission = Permission.by_id(permissionid) handler = Handler.by_name(name) if permission is None: return if handler is None: handler = Handler() handler.name = name handler.permission = permission self.db.add(handler) self.db.commit() flash(self, "处理器权限添加成功", "success")
def add_menu_lib(self, name, permissionid): """06为菜单添加权限函数""" permission = Permission.by_id(permissionid) if name == "" or permissionid == "": flash(self, "菜单名称或权限ID为空了,所以添加失败", "error") return menu = Menu.by_name(name)#注意 if menu is not None: flash(self, "菜单名称已存在,添加失败", "error") return menu = Menu() menu.name = name menu.permission = permission #问题 可不可以 #menu.p_id = permissionid ##这句话和上面这句效果一摸一样的,所以上面的写了这里就注释掉 self.db.add(menu) self.db.commit() flash(self, "菜单权限,添加成功", "success")
def permission_manage_list_lib(self): """01权限管理页面函数""" roles = Role.all() permissions = Permission.all() menus = Menu.all() handlers = Handler.all() users = User.all() # 研发员工 dev_role = Role.by_name('研发部门') dev_users = dev_role.users if dev_role else [] # print("*****") # print(type(dev_role)) # print(dev_role) if dev_role is None: return roles, permissions, menus, handlers, users, dev_users, None return roles, permissions, menus, handlers, users, dev_users, dev_role.id
def role_add_permission(self, permission_id, role_id): ''' 给角色增加权限 ''' role = Role.by_id(role_id) permission = Permission.by_id(permission_id) if permission is None: return {'status': False, 'msg': '不存在该权限ID'} if role is None: return {'status': False, 'msg': '不存在该角色ID'} ''' 第一种保存数据 permission_role = PermissionToRole() permission_role.r_id = role_id permission_role.p_id = permission_id ''' permission.roles.append(role) # 第二种 self.db.add(permission) self.db.commit() return {'status': True}
def menu_add_p_lib(self, name, permissionid): ''' 为菜单添加权限 ''' if name == '' or permissionid == '': return {'status': False, 'msg': '无效的权限ID'} permission = Permission.by_id(permissionid) if permission is None: return {'status': False, 'msg': '无效的权限ID'} menu = Menu.by_name(name) if menu: menu.p_id = permissionid self.db.add(menu) self.db.commit() return {'status': True} menu = Menu() menu.name = name menu.p_id = permissionid self.db.add(menu) self.db.commit() return {'status': True}
def add_handler(self, view_name, permission_id): ''' 为处理器添加权限 ''' if view_name == '' or permission_id == '': return {'status': False, 'msg': '请输入视图名和权限名'} permission = Permission.by_id(permission_id) if permission is None: return {'status': False, 'msg': '请输入有效的权限ID'} handler = Handler.by_name(view_name) if handler: handler.p_id = permission_id self.db.add(handler) self.db.commit() return {'status': True} handler = Handler() handler.name = view_name handler.p_id = permission_id self.db.add(handler) self.db.commit() return {'status': True}
def add_menu_lib(self, name, permissionid): """06添加菜单并为菜单添加权限""" permission = Permission.by_id(permissionid) menu = Menu.by_name(name) if permission is None: return if menu is None: menu = Menu() menu.name = name # print('**********') # print(type(menu)) # print(menu) # print(type(permission)) # print(permission) menu.permission = permission self.db.add(menu) self.db.commit() flash(self, "菜单权限添加成功", "success")
def add_handler_lib(self, name, permissionid): '''08添加处理器''' if not name or not permissionid: flash(self, '请输入处理器或权限id!', 'error') permission = Permission.by_id(permissionid) # 判断权限是否存在,不存在直接返回,存在,在验证菜单部分 if permission is None: flash(self, '该权限id不存在!', 'error') return handler = Handler.by_name(name) # 如果权限是空,则创建 if handler is None: handler = Handler() handler.name = name # 问题,这里可不可以添加进去 # 方法1:通过orm的方式添加数据 # handler.permission = permission # 方法2:同过数据库字段的方式添加数据 handler.p_id = permissionid self.db.add(handler) self.db.commit() flash(self, '处理器添加成功!', 'success')