hardware.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. @Web.auth
  11. @Web.setting
  12. def get(self):
  13. self.common(
  14. name = u'硬件设备'
  15. ,path = '/hardware/hardware'
  16. ,width = '600'
  17. ,height = '600'
  18. ,add = False
  19. ,edit = False
  20. ,search = (('farm_id-select-','hardware_type-select-','hardware_id-input-mlike'), (u'选择农场',u'硬件类型', u'硬件id'))
  21. ,thead = (u'所属农场', u'硬件类型', u'硬件id',u'网关名',u'设备名', u'接入时间')
  22. ,tbody = ('farm','type', 'hardware_id', 'gateway', 'device', 'cdate')
  23. ,state = False
  24. )
  25. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  26. self.data['common']['search_hardware_type-select-'] = self.service('common').list('hardware_type')
  27. self.commonList('hardware')
  28. if self.data['list']:
  29. for key, value in enumerate(self.data['list']):
  30. farm = self.service('common').one('farm', id=value['farm_id'])
  31. self.data['list'][key]['farm'] = farm['name']
  32. htype = self.service('common').one('hardware_type', id=value['hardware_type'])
  33. self.data['list'][key]['type'] = htype['name']
  34. gateway = self.service('common').one('device_gateway', id=value['gateway_id'])
  35. self.data['list'][key]['gateway'] = gateway['name']
  36. if value['device_id']:
  37. device = self.service('common').one('device_info', id=value['device_id'])
  38. self.data['list'][key]['device'] = device['name']
  39. else:
  40. self.data['list'][key]['device'] = ''
  41. self.commonView('list')
  42. class hardware_update_path(Load):
  43. @Web.auth
  44. @Web.setting
  45. def get(self):
  46. self.common(
  47. path = '/hardware/hardware'
  48. ,label = (u'硬件类型',u'硬件id')
  49. ,update = ('hardware_type-select-required','hardware_id-input-required')
  50. ,update_hardware_type = self.service('common').list('hardware_type')
  51. )
  52. self.commonOne('hardware')
  53. self.commonView('update')
  54. @Web.auth
  55. @Web.setting
  56. def post(self):
  57. self.commonUpdate('hardware')
  58. @Web.auth
  59. @Web.setting
  60. def delete(self):
  61. self.commonDelete('hardware')
  62. class type_path(Load):
  63. @Web.auth
  64. @Web.setting
  65. def get(self):
  66. self.common(
  67. name = u'硬件类型'
  68. ,path = '/hardware/type'
  69. ,width = '600'
  70. ,height = '300'
  71. ,search = (('name-input-mlike',), (u'类型名称',))
  72. ,thead = (u'类型名称',u'类型key', u'更新时间')
  73. ,tbody = ('name', 'key', 'cdate')
  74. ,state = False
  75. )
  76. self.commonList('hardware_type')
  77. self.commonView('list')
  78. class type_update_path(Load):
  79. @Web.auth
  80. @Web.setting
  81. def get(self):
  82. self.common(
  83. path = '/hardware/type'
  84. ,label = (u'类型名称', u'类型key')
  85. ,update = ('name-input-required', 'key-input-required')
  86. )
  87. self.commonOne('hardware_type')
  88. self.commonView('update')
  89. @Web.auth
  90. @Web.setting
  91. def post(self):
  92. self.commonUpdate('hardware_type')
  93. @Web.auth
  94. @Web.setting
  95. def delete(self):
  96. self.commonDelete('hardware_type')