work.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:work.py
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. class Work(object):
  9. @staticmethod
  10. def init(self, search={}):
  11. if 'set' in self.request.uri:
  12. self.data['work_cur'] = 'set'
  13. else:
  14. self.data['work_cur'] = 'index'
  15. self.data['url'] = Work.url()
  16. @staticmethod
  17. def url():
  18. config = {}
  19. config['index'] = '/work'
  20. config['set'] = '/work/set'
  21. return config
  22. class index_path(Load):
  23. @Web.auth
  24. @Web.setting
  25. def get(self):
  26. mobile = Demeter.checkMobile(self.request)
  27. if mobile:
  28. self.redirect('/device')
  29. return
  30. Work.init(self)
  31. self.data['list'] = self.service('common').list('farm_work', search={'farm_id':self.data['setting']['farm']})
  32. if self.data['list']:
  33. for key, value in enumerate(self.data['list']):
  34. self.data['list'][key]['workdates'] = Demeter.date(value['workdate'], '%Y-%m-%d %H:%M')
  35. category = self.service('common').one('farm_work_category', id=value['category_id'])
  36. self.data['list'][key]['category'] = category['name']
  37. method = self.service('common').one('farm_work_method', id=value['method_id'])
  38. self.data['list'][key]['method'] = method['name']
  39. land = self.service('common').one('farm_work_land', id=value['land_id'])
  40. self.data['list'][key]['land'] = land['name']
  41. self.view("work/index.html")
  42. class update_path(Load):
  43. @Web.auth
  44. @Web.setting
  45. def get(self):
  46. id = self.input('id')
  47. self.data['category'] = self.service('common').list('farm_work_category', search={'farm_id':self.data['setting']['farm']})
  48. self.data['method'] = self.service('common').list('farm_work_method', search={'farm_id':self.data['setting']['farm']})
  49. self.data['land'] = self.service('common').list('farm_work_land', search={'farm_id':self.data['setting']['farm']})
  50. self.data['info'] = {}
  51. if id:
  52. self.data['info'] = self.service('common').one('farm_work', id=id)
  53. if self.data['info'] and self.data['info']['workdate']:
  54. self.data['info']['workdate'] = Demeter.date(self.data['info']['workdate'])
  55. self.view("work/update.html")
  56. @Web.auth
  57. @Web.setting
  58. def post(self):
  59. id = self.input('id')
  60. update = {}
  61. update['amount'] = self.input('update_amount')
  62. update['category_id'] = self.input('update_category_id')
  63. update['method_id'] = self.input('update_method_id')
  64. update['land_id'] = self.input('update_land_id')
  65. update['pic'] = self.input('update_pic')
  66. update['workdate'] = self.input('update_workdate')
  67. if not update['category_id']:
  68. self.out(u'请选择劳作类别')
  69. return
  70. if not update['method_id'] or update['method_id'] == '0' or update['method_id'] == 0:
  71. self.out(u'请选择劳作方式')
  72. return
  73. if not update['land_id']:
  74. self.out(u'请选择操作地块')
  75. return
  76. if not update['workdate']:
  77. self.out(u'请选择农事日期')
  78. return
  79. if not update['amount']:
  80. self.out(u'请输入劳作用量')
  81. return
  82. if not update['pic']:
  83. self.out(u'请选择图片')
  84. return
  85. state = self.service('common').update('farm_work', id, update)
  86. self.out('yes', {'state':state})
  87. @Web.auth
  88. @Web.setting
  89. def delete(self):
  90. id = self.input('id')
  91. if not id:
  92. self.out('no')
  93. return
  94. state = self.input('state', False)
  95. state = self.service('common').delete('farm_work', id, state)
  96. self.out('yes', {'state':state})
  97. class set_path(Load):
  98. @Web.auth
  99. @Web.setting
  100. def get(self):
  101. Work.init(self)
  102. self.data['category'] = self.service('common').list('farm_work_category', search={'farm_id':self.data['setting']['farm']})
  103. self.data['method'] = self.service('common').list('farm_work_method', search={'farm_id':self.data['setting']['farm']})
  104. self.data['land'] = self.service('common').list('farm_work_land', search={'farm_id':self.data['setting']['farm']})
  105. self.view("work/set.html")
  106. class land_update_path(Load):
  107. @Web.auth
  108. @Web.setting
  109. def get(self):
  110. id = self.input('id')
  111. self.data['info'] = {}
  112. if id:
  113. self.data['info'] = self.service('common').one('farm_work_land', id=id)
  114. self.view("work/land_update.html")
  115. @Web.auth
  116. @Web.setting
  117. def post(self):
  118. id = self.input('id')
  119. update = {}
  120. update['name'] = self.input('update_name')
  121. if not update['name']:
  122. self.out(u'请输入地块名称')
  123. return
  124. state = self.service('common').update('farm_work_land', id, update)
  125. self.out('yes', {'state':state})
  126. @Web.auth
  127. @Web.setting
  128. def delete(self):
  129. id = self.input('id')
  130. if not id:
  131. self.out('no')
  132. return
  133. state = self.input('state', False)
  134. state = self.service('common').delete('farm_work_land', id, state)
  135. self.out('yes', {'state':state})
  136. class category_update_path(Load):
  137. @Web.auth
  138. @Web.setting
  139. def get(self):
  140. id = self.input('id')
  141. self.data['info'] = {}
  142. if id:
  143. self.data['info'] = self.service('common').one('farm_work_category', id=id)
  144. self.view("work/category_update.html")
  145. @Web.auth
  146. @Web.setting
  147. def post(self):
  148. id = self.input('id')
  149. update = {}
  150. update['name'] = self.input('update_name')
  151. if not update['name']:
  152. self.out(u'请输入农事内容分类名称')
  153. return
  154. state = self.service('common').update('farm_work_category', id, update)
  155. self.out('yes', {'state':state})
  156. @Web.auth
  157. @Web.setting
  158. def delete(self):
  159. id = self.input('id')
  160. if not id:
  161. self.out('no')
  162. return
  163. state = self.input('state', False)
  164. state = self.service('common').delete('farm_work_category', id, state)
  165. self.out('yes', {'state':state})
  166. class method_update_path(Load):
  167. @Web.auth
  168. @Web.setting
  169. def get(self):
  170. id = self.input('id')
  171. self.data['category'] = self.input('category')
  172. self.data['info'] = {}
  173. if id:
  174. self.data['info'] = self.service('common').one('farm_work_method', id=id)
  175. self.view("work/method_update.html")
  176. @Web.auth
  177. @Web.setting
  178. def post(self):
  179. id = self.input('id')
  180. update = {}
  181. update['name'] = self.input('update_name')
  182. update['category_id'] = self.input('update_category_id')
  183. if not update['name']:
  184. self.out(u'请输入农事内容名称')
  185. return
  186. if not update['category_id']:
  187. self.out(u'请选择农事分类')
  188. return
  189. state = self.service('common').update('farm_work_method', id, update)
  190. self.out('yes', {'state':state})
  191. @Web.auth
  192. @Web.setting
  193. def delete(self):
  194. id = self.input('id')
  195. if not id:
  196. self.out('no')
  197. return
  198. state = self.input('state', False)
  199. state = self.service('common').delete('farm_work_method', id, state)
  200. self.out('yes', {'state':state})