origin.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web page
  5. name:origin.py 溯源相关页面
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class batch_path(Load):
  10. @Web.auth
  11. @Web.setting
  12. def get(self):
  13. self.common(
  14. name = u'溯源批次'
  15. ,path = '/origin/batch'
  16. ,width = '600'
  17. ,height = '600'
  18. ,search = (('farm_id-select-','land_id-select-'), (u'选择农场',u'地块'))
  19. ,thead = (u'所属农场', u'产品名称', u'种植时间', u'采收时间', u'设备网关', u'地块')
  20. ,tbody = ('farm','name', 'zzdate', 'csdate', 'device', 'land')
  21. ,state = True
  22. )
  23. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  24. self.data['common']['search_land_id-select-'] = self.service('common').list('farm_work_land')
  25. farm_list = {}
  26. for value in self.data['common']['search_farm_id-select-']:
  27. farm_list[value['id']] = value
  28. farm_work_land = {}
  29. for value in self.data['common']['search_land_id-select-']:
  30. farm_work_land[value['id']] = value
  31. gateway = {}
  32. gateway_list = self.service('common').list('device_gateway')
  33. for value in gateway_list:
  34. gateway[value['id']] = value
  35. self.commonList('origin_batch')
  36. if self.data['list']:
  37. for key, value in enumerate(self.data['list']):
  38. self.data['list'][key]['land'] = '未知'
  39. farm = farm_list[value['farm_id']]
  40. self.data['list'][key]['farm'] = farm['name']
  41. device = gateway[value['gateway_id']]
  42. self.data['list'][key]['device'] = device['name']
  43. if value['land_id'] in farm_work_land:
  44. land = farm_work_land[value['land_id']]
  45. if land:
  46. self.data['list'][key]['land'] = land['name']
  47. self.commonView('list')
  48. class batch_update_path(Load):
  49. @Web.auth
  50. @Web.setting
  51. def get(self):
  52. self.common(
  53. path = '/origin/batch'
  54. ,label = (u'所属农场',u'产品名称', u'种植时间',u'采收时间',u'设备网关',u'地块',u'图像记录')
  55. ,update = ('farm_id-select-required','name-input-required', 'zzdate-date-required', 'csdate-date-required','gateway_id-select-required','land_id-select-required','pic-pic-required')
  56. ,update_gateway_id = self.service('common').list('device_gateway')
  57. ,update_land_id = self.service('common').list('farm_work_land')
  58. ,update_farm_id = Demeter.config['setting']['farmList']
  59. )
  60. self.commonOne('origin_batch')
  61. self.commonView('update')
  62. @Web.auth
  63. @Web.setting
  64. def post(self):
  65. self.commonUpdate('origin_batch')
  66. @Web.auth
  67. @Web.setting
  68. def delete(self):
  69. self.commonDelete('origin_batch')