consts.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # coding=utf-8
  2. CONTENT_TYPE_SORTING = (
  3. # 系统设置
  4. 'agent-agent', # 代理管理
  5. 'agent-store', # 门店管理
  6. 'account-user', # 用户管理
  7. 'account-managestoreuser', # 权限管理
  8. 'option-option', # 自定义项
  9. 'customer-reportcustomer', # 报备客户
  10. 'customer-newcustomer', # 潜客跟踪
  11. )
  12. MENU_TO_MODEL = (
  13. (
  14. u'基础数据', (
  15. 'account-user',
  16. 'account-managestoreuser',
  17. 'agent-agent',
  18. 'agent-store',
  19. 'option-option',
  20. )
  21. ),
  22. (
  23. u'潜客作业', (
  24. 'customer-reportcustomer',
  25. 'customer-newcustomer',
  26. )
  27. ),
  28. (
  29. u'订单管理', (
  30. 'order-order',
  31. )
  32. ),
  33. )
  34. class PermissionMenu(object):
  35. def __init__(self):
  36. self.sort = CONTENT_TYPE_SORTING
  37. self.menus = MENU_TO_MODEL
  38. def get_index(self, app_label, model):
  39. try:
  40. return self.sort.index('{}-{}'.format(app_label, model))
  41. except:
  42. return 9999
  43. def sort_perms(self, perms):
  44. perms = perms.order_by('content_type__model', 'id')
  45. perms = sorted(perms, key=lambda n: self.get_index(n.content_type.app_label, n.content_type.model))
  46. return perms
  47. def get_menuname_of_contenttype(self, app_label, model):
  48. for menu in self.menus:
  49. val = '{}-{}'.format(app_label, model)
  50. if val in menu[1]:
  51. return menu[0]
  52. return u'未分类'