work.py 6.5 KB

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