__load__.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. parent = [['农场与设备管理', '网站管理', '基础设置'],['', '', '']]
  49. child = [
  50. [['/farm/farm','/farm/product','/device/gateway','/device/info','/device/info?search_status-hidden-=1','/work/work','/work/category','/work/method','/work/land','/origin/batch','/farm/user','/device/printer','/msg/msg','/device/log'],['农场列表', '农场产品管理', '网关管理', '设备管理', '离线设备列表', '农场农事管理', '农场农事分类', '农场劳作方式', '农场地块管理', '溯源批次管理','农场用户管理','打印机管理', '消息提醒', '网关日志']]
  51. ,[['/web/set','/web/help_category','/web/help','/web/category','/web/article','/web/menu'],['网站资料设置', '帮助分类', '发布帮助内容', '文章分类', '发布内容文章', '菜单管理']]
  52. ,[['/device/type','/hardware/type','/device/notice_type','/msg/type','/admin/admin','/admin/role','/hardware/hardware', '/admin/log'],['设备类型管理','硬件类型管理', '设备错误码设置', '消息类型设置', '管理员设置', '管理权限设置','硬件设备记录', '系统日志']]
  53. #,[['/package/package','/package/version'],['Package管理', '版本管理']]
  54. ]
  55. return (parent,child)