consts.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # coding=utf-8
  2. CONTENT_TYPE_SORTING = (
  3. # 系统设置
  4. 'area-area', # 区域设置
  5. 'building-building', # 建筑信息
  6. 'equipment-equipment', # 设备信息
  7. 'employee-employee', # 员工管理
  8. 'option-option', # 系统选项
  9. 'config-config', # 基础设置
  10. 'account-user', # 权限管理
  11. 'repair_order-repairorder', # 报修管理
  12. 'inspection_order-inspectionorder', # 巡检管理
  13. )
  14. MENU_TO_MODEL = (
  15. (
  16. u'系统设置', (
  17. 'area-area',
  18. 'building-building',
  19. 'equipment-equipment',
  20. 'employee-employee',
  21. 'option-option',
  22. 'config-config',
  23. 'account-user',
  24. )
  25. ),
  26. (
  27. u'报修管理', (
  28. 'repair_order-repairorder',
  29. )
  30. ),
  31. (
  32. u'巡检管理', (
  33. 'inspection_order-inspectionorder',
  34. )
  35. ),
  36. )
  37. class PermissionMenu(object):
  38. def __init__(self):
  39. self.sort = CONTENT_TYPE_SORTING
  40. self.menus = MENU_TO_MODEL
  41. def get_index(self, app_label, model):
  42. try:
  43. return self.sort.index('{}-{}'.format(app_label, model))
  44. except:
  45. return 9999
  46. def sort_perms(self, perms):
  47. perms = perms.order_by('content_type__model', 'id')
  48. perms = sorted(perms, key=lambda n: self.get_index(n.content_type.app_label, n.content_type.model))
  49. return perms
  50. def get_menuname_of_contenttype(self, app_label, model):
  51. for menu in self.menus:
  52. val = '{}-{}'.format(app_label, model)
  53. if val in menu[1]:
  54. return menu[0]
  55. return u'未分类'