main.py 6.3 KB

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