__load__.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter load
  5. author:rabin
  6. """
  7. from demeter.web import *
  8. class Load(Base):
  9. KEYS = ('admin', 'farm')
  10. def setting(self):
  11. self.search()
  12. self.admin()
  13. def admin(self):
  14. admin = 1
  15. self.data['auth'] = True
  16. if 'admin' in self.data['setting'] and self.data['setting']['admin'] > 0:
  17. self.data['setting']['adminInfo'] = self.service('common').one('manage_admin', id=self.data['setting']['admin'])
  18. if self.data['setting']['adminInfo']:
  19. self.data['setting']['roleInfo'] = self.service('common').one('manage_role', id=self.data['setting']['adminInfo']['role_id'])
  20. else:
  21. #self.redirect('/user/login')
  22. return
  23. if 'farm' in self.data['setting'] and self.data['setting']['farm'] > 0:
  24. self.data['setting']['farmInfo'] = self.service('common').one('farm', id=self.data['setting']['farm'])
  25. self.data['setting']['menuList'] = self.menu()
  26. if self.data['setting']['adminInfo']['id'] == admin:
  27. if 'menu' in self.data['setting']:
  28. del self.data['setting']['menu']
  29. else:
  30. self.data['setting']['menu'] = ['_/', '_/login', '_/main', '_/admin/log_update']
  31. menu = self.data['setting']['roleInfo']['auth'] + ','
  32. for i,j in enumerate(self.data['setting']['menuList'][1]):
  33. m = 0
  34. for n in j[0]:
  35. if n+',' in menu:
  36. l = str(i)+'_'+str(n)
  37. self.data['setting']['menu'].append(l)
  38. self.data['setting']['menu'].append(l + '_update')
  39. m = m + 1
  40. self.data['setting']['menu'] = ',' + ",".join(self.data['setting']['menu'])+','
  41. uri = '_' + self.request.uri + ','
  42. if self.data['setting']['admin'] != admin and uri not in self.data['setting']['menu']:
  43. self.data['auth'] = False
  44. self.data['setting']['web'] = Demeter.config['web']['url']
  45. self.data['setting']['farmList'] = self.service('common').list('farm')
  46. def menu(self):
  47. parent = [['农场与设备管理', '网站管理', '基础设置'],['', '', '']]
  48. child = [
  49. [['/farm/farm','/device/gateway','/device/info','/work/work','/work/land','/origin/batch','/farm/user','/device/printer','/msg/msg','/device/log'],['农场列表', '网关管理', '设备管理', '农场农事管理', '农场地块管理', '溯源批次管理','农场用户管理','农场打印机','消息提醒', '网关日志']]
  50. ,[['/web/set','/web/category','/web/article','/web/menu'],['首页内容管理', '文章分类', '发布内容文章', '菜单管理']]
  51. ,[['/device/type','/hardware/type','/msg/type','/work/category','/admin/admin','/admin/role','/hardware/hardware', '/admin/log'],['设备类型管理','硬件类型管理', '消息类型设置', '农事类型设置', '管理员设置', '管理权限设置','硬件设备记录', '系统日志']]
  52. ]
  53. return (parent,child)