work.py 6.5 KB

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