hardware.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web page
  5. name:hardware.py 硬件相关页面
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class hardware_path(Load):
  10. @tornado.web.authenticated
  11. def get(self):
  12. self.common(
  13. name = u'硬件设备'
  14. ,path = '/hardware/hardware'
  15. ,width = '600'
  16. ,height = '600'
  17. ,add = False
  18. ,edit = False
  19. ,search = (('farm_id-select-','hardware_type-select-','hardware_id-input-mlike'), (u'选择农场',u'硬件类型', u'硬件id'))
  20. ,thead = (u'所属农场', u'硬件类型', u'硬件id',u'网关名',u'设备名', u'接入时间')
  21. ,tbody = ('farm','type', 'hardware_id', 'gateway', 'device', 'cdate')
  22. ,state = False
  23. )
  24. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  25. self.data['common']['search_hardware_type-select-'] = self.service('common').list('hardware_type')
  26. self.commonList('hardware')
  27. if self.data['list']:
  28. for key, value in enumerate(self.data['list']):
  29. farm = self.service('common').one('farm', id=value['farm_id'])
  30. self.data['list'][key]['farm'] = farm['name']
  31. htype = self.service('common').one('hardware_type', id=value['hardware_type'])
  32. self.data['list'][key]['type'] = htype['name']
  33. gateway = self.service('common').one('device_gateway', id=value['gateway_id'])
  34. self.data['list'][key]['gateway'] = gateway['name']
  35. if value['device_id']:
  36. device = self.service('common').one('device_info', id=value['device_id'])
  37. self.data['list'][key]['device'] = device['name']
  38. else:
  39. self.data['list'][key]['device'] = ''
  40. self.commonView('list')
  41. class hardware_update_path(Load):
  42. @tornado.web.authenticated
  43. def get(self):
  44. self.common(
  45. path = '/hardware/hardware'
  46. ,label = (u'硬件类型',u'硬件id')
  47. ,update = ('hardware_type-select-required','hardware_id-input-required')
  48. ,update_hardware_type = self.service('common').list('hardware_type')
  49. )
  50. self.commonOne('hardware')
  51. self.commonView('update')
  52. @tornado.web.authenticated
  53. def post(self):
  54. self.commonUpdate('hardware')
  55. @tornado.web.authenticated
  56. def delete(self):
  57. self.commonDelete('hardware')
  58. class type_path(Load):
  59. @tornado.web.authenticated
  60. def get(self):
  61. self.common(
  62. name = u'硬件类型'
  63. ,path = '/hardware/type'
  64. ,width = '600'
  65. ,height = '300'
  66. ,search = (('name-input-mlike',), (u'类型名称',))
  67. ,thead = (u'类型名称',u'类型key', u'更新时间')
  68. ,tbody = ('name', 'key', 'cdate')
  69. ,state = False
  70. )
  71. self.commonList('hardware_type')
  72. self.commonView('list')
  73. class type_update_path(Load):
  74. @tornado.web.authenticated
  75. def get(self):
  76. self.common(
  77. path = '/hardware/type'
  78. ,label = (u'类型名称', u'类型key')
  79. ,update = ('name-input-required', 'key-input-required')
  80. )
  81. self.commonOne('hardware_type')
  82. self.commonView('update')
  83. @tornado.web.authenticated
  84. def post(self):
  85. self.commonUpdate('hardware_type')
  86. @tornado.web.authenticated
  87. def delete(self):
  88. self.commonDelete('hardware_type')