consts.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # coding=utf-8
  2. CONTENT_TYPE_SORTING = (
  3. # 系统设置
  4. 'account-user', # 用户管理
  5. 'account-manageagentuser', # 权限管理
  6. 'option-option', # 自定义项
  7. 'option-agentlevel', # 代理商等级
  8. 'commodity-commodity', # 商品管理
  9. 'commodity-commodityparameter', # 商品参数
  10. 'agent-agentapply', # 代理商申请
  11. 'agent-agent', # 代理商
  12. 'agent-agentcommodity', # 代理商商品
  13. 'order-order', # 代理商订单
  14. 'WechatApplet-wechatapplet', # 小程序管理
  15. 'deliver-productdeliver', # 防窜货管理
  16. )
  17. MENU_TO_MODEL = (
  18. (
  19. u'基础数据', (
  20. 'account-user',
  21. 'account-manageagentuser',
  22. 'option-option',
  23. 'option-agentlevel',
  24. )
  25. ),
  26. (
  27. u'商品管理', (
  28. 'commodity-commodity',
  29. 'commodity-commodityparameter',
  30. )
  31. ),
  32. (
  33. u'代理商管理', (
  34. 'agent-agentapply',
  35. 'agent-agent',
  36. 'agent-agentcommodity',
  37. 'order-order',
  38. )
  39. ),
  40. (
  41. u'其他', (
  42. 'WechatApplet-wechatapplet',
  43. 'deliver-productdeliver',
  44. ),
  45. ),
  46. )
  47. class PermissionMenu(object):
  48. def __init__(self):
  49. self.sort = CONTENT_TYPE_SORTING
  50. self.menus = MENU_TO_MODEL
  51. def get_index(self, app_label, model):
  52. try:
  53. return self.sort.index('{}-{}'.format(app_label, model))
  54. except:
  55. return 9999
  56. def sort_perms(self, perms):
  57. perms = perms.order_by('content_type__model', 'id')
  58. perms = sorted(perms, key=lambda n: self.get_index(n.content_type.app_label, n.content_type.model))
  59. return perms
  60. def get_menuname_of_contenttype(self, app_label, model):
  61. for menu in self.menus:
  62. val = '{}-{}'.format(app_label, model)
  63. if val in menu[1]:
  64. return menu[0]
  65. return u'未分类'