main.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web page
  5. name:main.py
  6. author:rabin
  7. """
  8. from .__load__ import *
  9. class Farm(object):
  10. @staticmethod
  11. def init(self, search={}):
  12. if 'edit' in self.request.uri:
  13. self.data['farm_cur'] = 'edit'
  14. elif 'product' in self.request.uri:
  15. self.data['farm_cur'] = 'product'
  16. elif 'env' in self.request.uri:
  17. self.data['farm_cur'] = 'env'
  18. else:
  19. self.data['farm_cur'] = 'index'
  20. self.data['url'] = Farm.url()
  21. @staticmethod
  22. def url():
  23. config = {}
  24. config['info'] = '/'
  25. config['edit'] = '/main/edit'
  26. config['product'] = '/main/product'
  27. config['env'] = '/main/env'
  28. return config
  29. class index_path(Load):
  30. @Web.auth
  31. @Web.setting
  32. def get(self):
  33. if 'url' in self.data:
  34. self.redirect(self.data['url'])
  35. mobile = Demeter.checkMobile(self.request)
  36. if mobile:
  37. self.redirect('/device')
  38. return
  39. Farm.init(self)
  40. self.view("farm/index.html")
  41. @Web.auth
  42. @Web.setting
  43. def post(self):
  44. id = self.data['setting']['farm']
  45. update = {}
  46. update['info'] = self.input('update_info')
  47. if not update['info']:
  48. self.out(u'请输入农场介绍')
  49. return
  50. state = self.service('common').update('farm', id, update)
  51. self.out('修改成功')
  52. class edit_path(Load):
  53. @Web.auth
  54. @Web.setting
  55. def get(self):
  56. Farm.init(self)
  57. self.view("farm/edit.html")
  58. @Web.auth
  59. @Web.setting
  60. def post(self):
  61. id = self.data['setting']['farm']
  62. update = {}
  63. update['name'] = self.input('update_name')
  64. update['pic'] = self.input('update_pic')
  65. update['location'] = self.input('update_location')
  66. update['master_name'] = self.input('update_master_name')
  67. update['master_pic'] = self.input('update_master_pic')
  68. update['tel'] = self.input('update_tel')
  69. update['address'] = self.input('update_address')
  70. update['welcome'] = self.input('update_welcome')
  71. if not update['name']:
  72. self.out(u'请输入名称')
  73. return
  74. if not update['pic']:
  75. self.out(u'请选择图片')
  76. return
  77. if not update['location']:
  78. self.out(u'请输入位置')
  79. return
  80. if not update['master_name']:
  81. self.out(u'请输入姓名')
  82. return
  83. if not update['master_pic']:
  84. self.out(u'请选择图片')
  85. return
  86. if not update['tel']:
  87. self.out(u'请输入联系电话')
  88. return
  89. if not update['address']:
  90. self.out(u'请输入联系地址')
  91. return
  92. state = self.service('common').update('farm', id, update)
  93. self.out('修改成功')
  94. @Web.auth
  95. @Web.setting
  96. def delete(self):
  97. id = self.input('id')
  98. if not id:
  99. self.out('no')
  100. return
  101. state = self.service('common').rDelete('farm', id)
  102. self.out('yes', {'state':state})
  103. class product_path(Load):
  104. @Web.auth
  105. @Web.setting
  106. def get(self):
  107. Farm.init(self)
  108. self.data['list'] = self.service('common').list('farm_product', search={'farm_id':self.data['setting']['farm']})
  109. self.view("farm/product.html")
  110. class product_update_path(Load):
  111. @Web.auth
  112. @Web.setting
  113. def get(self):
  114. id = self.input('id')
  115. self.data['info'] = {}
  116. if id:
  117. self.data['info'] = self.service('common').one('farm_product', id=id)
  118. self.view("farm/product_update.html")
  119. @Web.auth
  120. @Web.setting
  121. def post(self):
  122. id = self.input('id')
  123. update = {}
  124. update['name'] = self.input('update_name')
  125. update['pic'] = self.input('update_pic')
  126. update['area'] = self.input('update_area')
  127. update['yields'] = self.input('update_yields')
  128. update['charact'] = self.input('update_charact')
  129. update['notice'] = self.input('update_notice')
  130. if not update['name']:
  131. self.out(u'请输入名称')
  132. return
  133. if not update['area']:
  134. self.out(u'请输入种植面积')
  135. return
  136. if not update['yields']:
  137. self.out(u'请输入平均亩产')
  138. return
  139. """
  140. if not update['charact']:
  141. self.out(u'请输入特点')
  142. return
  143. if not update['notice']:
  144. self.out(u'请输入使用须知')
  145. return
  146. """
  147. if not update['pic']:
  148. self.out(u'请选择图片')
  149. return
  150. state = self.service('common').update('farm_product', id, update)
  151. self.out('yes', {'state':state})
  152. @Web.auth
  153. @Web.setting
  154. def delete(self):
  155. id = self.input('id')
  156. if not id:
  157. self.out('no')
  158. return
  159. state = self.input('state', '1')
  160. update = {}
  161. if state == '1':
  162. update['status'] = True
  163. else:
  164. update['status'] = False
  165. state = self.service('common').update('farm_product', id, update)
  166. self.out('yes', {'state':state})
  167. class env_path(Load):
  168. @Web.auth
  169. @Web.setting
  170. def get(self):
  171. Farm.init(self)
  172. self.data['list'] = self.service('common').list('farm_env', order='inorder asc,cdate desc', search={'farm_id':self.data['setting']['farm']})
  173. if self.data['list']:
  174. for key, value in enumerate(self.data['list']):
  175. info = self.service('common').one('device_info', id=value['device_id'])
  176. self.data['list'][key]['device'] = info
  177. info = self.service('common').one('device_type', id=value['type_id'])
  178. self.data['list'][key]['type'] = info
  179. self.view("farm/env.html")
  180. class env_update_path(Load):
  181. @Web.auth
  182. @Web.setting
  183. def get(self):
  184. id = self.input('id')
  185. self.data['info'] = {}
  186. if id:
  187. self.data['info'] = self.service('common').one('farm_env', id=id)
  188. self.data['gateway'] = self.service('common').list('device_gateway', search={'farm_id':self.data['setting']['farm']})
  189. self.data['device'] = Device.getByGateway(self, search={'hardware_type' : 2,'farm_id':self.data['setting']['farm']})
  190. self.view("farm/env_update.html")
  191. @Web.auth
  192. @Web.setting
  193. def post(self):
  194. id = self.input('id')
  195. update = {}
  196. update['name'] = self.input('update_name')
  197. update['device_id'] = self.input('update_device_id')
  198. update['inorder'] = self.input('update_inorder', 0)
  199. if not update['name']:
  200. self.out(u'请输入环境名称')
  201. return
  202. if not update['device_id']:
  203. self.out(u'请选择设备')
  204. return
  205. if not update['inorder']:
  206. update['inorder'] = 0
  207. """
  208. if update['inorder'] and not Check.number(update['inorder']):
  209. self.out(u'排序必须是数字')
  210. return
  211. """
  212. device = self.service('common').one('device_info', id=update['device_id'])
  213. if not device:
  214. self.out(u'请选择设备')
  215. return
  216. update['type_id'] = device['type_id']
  217. state = self.service('common').update('farm_env', id, update)
  218. self.out('yes', {'state':state})
  219. @Web.auth
  220. @Web.setting
  221. def delete(self):
  222. id = self.input('id')
  223. if not id:
  224. self.out('no')
  225. return
  226. state = self.input('state', False)
  227. state = self.service('common').rDelete('farm_env', id)
  228. self.out('yes', {'state':state})