标签:pen 个人 apt 微软 中间 led dmi normal port
#########################################################
# rbac 权限相关配置 #
#########################################################
# 保存用户权限的session key
SESSION_PERMISSION_URL_KEY = "sanhdfiuhasakdjflkajsf"
SESSION_PERMISSION_MENU_URL_KEY = "sjdiuwekljdsksdfjlskdsd"
ALL_MENU_KEY = "k1"
PERMISSION_URL_KEY = "k2"
from django.conf import settings
from .. import models
def init_permission(request,user_obj):
"""
初始化用户权限
:param request:
:param user_obj:
:return:
"""
# distinct()去掉重复,values可以取roles对应的多对多的表的字段
permission_item_list = user_obj.roles.values(‘permissions__title‘,‘permissions__url‘,
‘permissions__menu_id‘).distinct()
# 保存当前用户有权访问的URL
permission_url_list = []
# 保存当前用户有权访问的URL且需要在菜单上显示
permission_menu_list = []
for item in permission_item_list:
"""
循环这个query_set集合,取需要的数据
"""
permission_url_list.append(item[‘permissions__url‘])
if item[‘permissions__menu_id‘]:
temp = {‘title‘:item[‘permissions__title‘],‘url‘:item[‘permissions__url‘],
‘menu_id‘:item[‘permissions__menu_id‘]}
permission_menu_list.append(temp)
# 所有菜单
menu_lsit = list(models.Menu.objects.values(‘caption‘,‘parent_id‘))
request.session[settings.SESSION_PERMISSION_URL_KEY] = permission_url_list
request.session[settings.SESSION_PERMISSION_MENU_URL_KEY] = {
settings.PERMISSION_URL_KEY:permission_menu_list,
settings.ALL_MENU_KEY: menu_lsit, }
python manage.py startapp rbac
#########################################################
# rbac 权限相关配置 #
#########################################################
# 保存用户权限的session key
SESSION_PERMISSION_URL_KEY = "sanhdfiuhasakdjflkajsf"
SESSION_PERMISSION_MENU_URL_KEY = "sjdiuwekljdsksdfjlskdsd"
ALL_MENU_KEY = "k1"
PERMISSION_URL_KEY = "k2"
from django.conf import settings
from .. import models
def init_permission(request,user_obj):
"""
初始化用户权限
:param request:
:param user_obj:
:return:
"""
# distinct()去掉重复,values可以取roles对应的多对多的表的字段
permission_item_list = user_obj.roles.values(‘permissions__title‘,‘permissions__url‘,
‘permissions__menu_id‘).distinct()
# 保存当前用户有权访问的URL
permission_url_list = []
# 保存当前用户有权访问的URL且需要在菜单上显示
permission_menu_list = []
for item in permission_item_list:
"""
循环这个query_set集合,取需要的数据
"""
permission_url_list.append(item[‘permissions__url‘])
if item[‘permissions__menu_id‘]:
temp = {‘title‘:item[‘permissions__title‘],‘url‘:item[‘permissions__url‘],
‘menu_id‘:item[‘permissions__menu_id‘]}
permission_menu_list.append(temp)
# 所有菜单
menu_lsit = list(models.Menu.objects.values(‘caption‘,‘parent_id‘))
request.session[settings.SESSION_PERMISSION_URL_KEY] = permission_url_list
request.session[settings.SESSION_PERMISSION_MENU_URL_KEY] = {
settings.PERMISSION_URL_KEY:permission_menu_list,
settings.ALL_MENU_KEY: menu_lsit, }
#########################################################
# rbac 权限相关配置 #
#########################################################
# 保存用户权限的session key
SESSION_PERMISSION_URL_KEY = "sanhdfiuhasakdjflkajsf"
SESSION_PERMISSION_MENU_URL_KEY = "sjdiuwekljdsksdfjlskdsd"
ALL_MENU_KEY = "k1"
PERMISSION_URL_KEY = "k2"
标签:pen 个人 apt 微软 中间 led dmi normal port
原文地址:http://www.cnblogs.com/lucaq/p/7575585.html