work.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web page
  5. name:work.py 农事相关页面
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class work_path(Load):
  10. @Web.auth
  11. @Web.setting
  12. def get(self):
  13. self.common(
  14. name = u'农事'
  15. ,path = '/work/work'
  16. ,width = '600'
  17. ,height = '600'
  18. ,search = (('label-1','workdate-time-start','workdate-time-end','farm_id-select-','category_id-select-'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'劳作方式'))
  19. ,thead = (u'所属农场', u'劳作时间', u'劳作方式', u'劳作地块', u'劳作用量', u'更新时间')
  20. ,tbody = ('farm','workdate', 'category', 'land', 'amount', 'cdate')
  21. ,state = True
  22. )
  23. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  24. self.data['common']['search_category_id-select-'] = self.service('common').list('farm_work_category')
  25. farm_list = {}
  26. for value in self.data['common']['search_farm_id-select-']:
  27. farm_list[value['id']] = value
  28. gateway = {}
  29. for value in self.data['common']['search_category_id-select-']:
  30. gateway[value['id']] = value
  31. farm_work_land = {}
  32. for value in self.service('common').list('farm_work_land'):
  33. farm_work_land[value['id']] = value
  34. self.commonList('farm_work')
  35. if self.data['list']:
  36. for key, value in enumerate(self.data['list']):
  37. self.data['list'][key]['land'] = '未知'
  38. farm = farm_list[value['farm_id']]
  39. self.data['list'][key]['farm'] = farm['name']
  40. category = self.service('common').one('farm_work_category', id=value['category_id'])
  41. self.data['list'][key]['category'] = category['name']
  42. if value['land_id'] in farm_work_land:
  43. land = farm_work_land[value['land_id']]
  44. if land:
  45. self.data['list'][key]['land'] = land['name']
  46. self.commonView('list')
  47. class work_update_path(Load):
  48. @Web.auth
  49. @Web.setting
  50. def get(self):
  51. self.common(
  52. path = '/work/work'
  53. ,label = (u'所属农场',u'劳作时间',u'劳作方式',u'劳作用量',u'劳作地块',u'图像记录',u'劳作内容')
  54. ,update = ('farm_id-select-required', 'workdate-date-required','category_id-select-required','amount-input-required','land_id-select-required','pic-pic-required','content-text-required')
  55. ,update_category_id = self.service('common').list('farm_work_category')
  56. ,update_land_id = self.service('common').list('farm_work_land')
  57. ,update_farm_id = Demeter.config['setting']['farmList']
  58. )
  59. self.commonOne('farm_work')
  60. self.commonView('update')
  61. @Web.auth
  62. @Web.setting
  63. def post(self):
  64. self.commonUpdate('farm_work')
  65. @Web.auth
  66. @Web.setting
  67. def delete(self):
  68. self.commonDelete('farm_work')
  69. class category_path(Load):
  70. @Web.auth
  71. @Web.setting
  72. def get(self):
  73. self.common(
  74. name = u'劳作方式'
  75. ,path = '/work/category'
  76. ,width = '600'
  77. ,height = '250'
  78. ,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'方式名称'))
  79. ,thead = (u'方式名称', u'更新时间')
  80. ,tbody = ('name', 'cdate')
  81. ,state = True
  82. )
  83. self.commonList('farm_work_category')
  84. self.commonView('list')
  85. class category_update_path(Load):
  86. @Web.auth
  87. @Web.setting
  88. def get(self):
  89. self.common(
  90. path = '/work/category'
  91. ,label = (u'方式名称',)
  92. ,update = ('name-input-required',)
  93. )
  94. self.commonOne('farm_work_category')
  95. self.commonView('update')
  96. @Web.auth
  97. @Web.setting
  98. def post(self):
  99. self.commonUpdate('farm_work_category')
  100. @Web.auth
  101. @Web.setting
  102. def delete(self):
  103. self.commonDelete('farm_work_category')
  104. class land_path(Load):
  105. @Web.auth
  106. @Web.setting
  107. def get(self):
  108. self.common(
  109. name = u'地块'
  110. ,path = '/work/land'
  111. ,width = '600'
  112. ,height = '250'
  113. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'地块名称'))
  114. ,thead = (u'所属农场',u'地块名称', u'更新时间')
  115. ,tbody = ('farm', 'name', 'cdate')
  116. ,state = True
  117. )
  118. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  119. self.commonList('farm_work_land')
  120. if self.data['list']:
  121. for key, value in enumerate(self.data['list']):
  122. farm = self.service('common').one('farm', id=value['farm_id'])
  123. self.data['list'][key]['farm'] = farm['name']
  124. self.commonView('list')
  125. class land_update_path(Load):
  126. @Web.auth
  127. @Web.setting
  128. def get(self):
  129. self.common(
  130. path = '/work/land'
  131. ,label = (u'所属农场', u'地块名称')
  132. ,update = ('farm_id-select-required','name-input-required')
  133. ,update_farm_id = Demeter.config['setting']['farmList']
  134. )
  135. self.commonOne('farm_work_land')
  136. self.commonView('update')
  137. @Web.auth
  138. @Web.setting
  139. def post(self):
  140. self.commonUpdate('farm_work_land')
  141. @Web.auth
  142. @Web.setting
  143. def delete(self):
  144. self.commonDelete('farm_work_land')