consts.py 1.4 KB

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