123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- # coding=utf-8
- CONTENT_TYPE_SORTING = (
- # 系统设置
- 'account-user', # 用户管理
- 'account-manageagentuser', # 权限管理
- 'option-option', # 自定义项
- 'option-agentlevel', # 代理商等级
- 'commodity-commodity', # 商品管理
- 'commodity-commodityparameter', # 商品参数
- 'agent-agentapply', # 代理商申请
- 'agent-agent', # 代理商
- 'agent-agentcommodity', # 代理商商品
- 'order-order', # 代理商订单
- 'WechatApplet-wechatapplet', # 小程序管理
- 'deliver-productdeliver', # 防窜货管理
- )
- MENU_TO_MODEL = (
- (
- u'基础数据', (
- 'account-user',
- 'account-manageagentuser',
- 'option-option',
- 'option-agentlevel',
- )
- ),
- (
- u'商品管理', (
- 'commodity-commodity',
- 'commodity-commodityparameter',
- )
- ),
- (
- u'代理商管理', (
- 'agent-agentapply',
- 'agent-agent',
- 'agent-agentcommodity',
- 'order-order',
- )
- ),
- (
- u'其他', (
- 'WechatApplet-wechatapplet',
- 'deliver-productdeliver',
- ),
- ),
- )
- class PermissionMenu(object):
- def __init__(self):
- self.sort = CONTENT_TYPE_SORTING
- self.menus = MENU_TO_MODEL
- def get_index(self, app_label, model):
- try:
- return self.sort.index('{}-{}'.format(app_label, model))
- except:
- return 9999
- def sort_perms(self, perms):
- perms = perms.order_by('content_type__model', 'id')
- perms = sorted(perms, key=lambda n: self.get_index(n.content_type.app_label, n.content_type.model))
- return perms
- def get_menuname_of_contenttype(self, app_label, model):
- for menu in self.menus:
- val = '{}-{}'.format(app_label, model)
- if val in menu[1]:
- return menu[0]
- return u'未分类'
|