consts.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. )
  11. MENU_TO_MODEL = (
  12. (
  13. u'基础数据', (
  14. 'account-user',
  15. 'account-managestoreuser',
  16. 'agent-agent',
  17. 'agent-store',
  18. 'option-option',
  19. )
  20. ),
  21. (
  22. u'潜客作业', (
  23. 'customer-reportcustomer',
  24. )
  25. ),
  26. (
  27. u'订单管理', (
  28. 'order-order',
  29. )
  30. ),
  31. )
  32. class PermissionMenu(object):
  33. def __init__(self):
  34. self.sort = CONTENT_TYPE_SORTING
  35. self.menus = MENU_TO_MODEL
  36. def get_index(self, app_label, model):
  37. try:
  38. return self.sort.index('{}-{}'.format(app_label, model))
  39. except:
  40. return 9999
  41. def sort_perms(self, perms):
  42. perms = perms.order_by('content_type__model', 'id')
  43. perms = sorted(perms, key=lambda n: self.get_index(n.content_type.app_label, n.content_type.model))
  44. return perms
  45. def get_menuname_of_contenttype(self, app_label, model):
  46. for menu in self.menus:
  47. val = '{}-{}'.format(app_label, model)
  48. if val in menu[1]:
  49. return menu[0]
  50. return u'未分类'