farm.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:farm.py 农场相关页面
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. farm = {
  9. 'id' : int(Demeter.config['setting']['farm'])
  10. }
  11. class farm_path(Load):
  12. @Web.auth
  13. @Web.setting
  14. def get(self):
  15. self.set(
  16. name = u'农场' #中文名
  17. ,path = '/farm/farm' #路径
  18. ,width = '600' # 新增页面的宽度
  19. ,height = '600' # 新增页面的高度
  20. ,edit = False
  21. ,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'农场名称')) #搜索
  22. ,thead = (u'ID', u'农场名称', u'状态', u'功能列表') #表头
  23. ,tbody = ('id','name', 'status', 'func') #表内容
  24. ,state = False #启用回收站
  25. )
  26. menu = (
  27. {'name':'基础资料', 'url':'/farm/info'}
  28. ,{'name':'用户管理', 'url':'/farm/user'}
  29. ,{'name':'产品管理', 'url':'/farm/product'}
  30. ,{'name':'地块管理', 'url':'/work/land'}
  31. ,{'name':'农事管理', 'url':'/work/work'}
  32. ,{'name':'批次管理', 'url':'/origin/batch'}
  33. ,{'name':'网关管理', 'url':'/device/gateway'}
  34. ,{'name':'设备管理', 'url':'/device/info'}
  35. #,{'name':'生成本地控制器', 'url':'/package/download'}
  36. #,{'name':'打印机管理', 'url':'/device/printer'}
  37. #,{'name':'消息提醒', 'url':'/msg/msg'}
  38. #,{'name':'网关日志', 'url':'/device/log'}
  39. )
  40. control = {'name':'本地控制', 'url':'/package/download'}
  41. self.list('farm')
  42. if self.data['list']:
  43. for key, value in enumerate(self.data['list']):
  44. id = str(value['id'])
  45. param = '?farm=' + id + '&search_farm_id-select-=' + id
  46. self.data['list'][key]['status'] = '云端'
  47. if value['eros_status'] == 1:
  48. self.data['list'][key]['status'] = '本地:' + value['eros_server']
  49. self.data['list'][key]['func'] = ''
  50. for i in menu:
  51. self.data['list'][key]['func'] = self.data['list'][key]['func'] + '<a href="'+i['url']+''+param+'">'+i['name']+'</a>&nbsp;&nbsp;&nbsp;&nbsp;'
  52. self.show('list')
  53. class farm_update_path(Load):
  54. @Web.auth
  55. @Web.setting
  56. def get(self):
  57. self.set(
  58. path = '/farm/farm'
  59. ,label = (u'农场名称',)
  60. ,update = ('name-input-required',)
  61. )
  62. self.one('farm')
  63. self.show('update')
  64. @Web.auth
  65. @Web.setting
  66. def post(self):
  67. id = self.update('farm')
  68. Demeter.config['setting']['farmList'] = self.service('common').list('farm')
  69. #self.gateway(id)
  70. def gateway(self, farm):
  71. gateway = self.data['update']['gateway']
  72. if gateway:
  73. #换行隔开,逗号隔开,插入到网关表里
  74. data = gateway.split("\r\n")
  75. for value in data:
  76. if ',' in value:
  77. value = value.split(',')
  78. else:
  79. value[0] = value
  80. value[1] = '网关' + value
  81. info = self.service('common').one('device_gateway', hardware_id=value[0])
  82. if not info:
  83. insert = {}
  84. insert['farm_id'] = farm
  85. insert['name'] = value[1]
  86. insert['hardware_id'] = value[0]
  87. self.service('common').update('device_gateway', None, insert)
  88. else:
  89. update = {}
  90. update['name'] = value[1]
  91. self.service('common').update('device_gateway', info['id'], update)
  92. class info_path(Load):
  93. @Web.auth
  94. @Web.setting
  95. def get(self):
  96. id = self.input('farm')
  97. param = '?farm=' + id
  98. self.set(
  99. path = '/farm/info' + param
  100. ,label = (u'农场名称',u'农场图片',u'农场位置',u'联系电话',u'联系地址',u'农场主姓名',u'农场主照片',u'欢迎语',u'农场介绍')
  101. ,update = ('name-input-required','pic-pic-required-1000px*300~450px','location-input-required','tel-input-required','address-input-required','master_name-input-required','master_pic-pic-required-300px*450px','welcome-input-',u'info-text-required-请输入农场介绍')
  102. ,update_eros_status = Demeter.service('core', 'setting').eros_status()
  103. )
  104. self.one('farm', id=id)
  105. self.show('set')
  106. @Web.auth
  107. @Web.setting
  108. def post(self):
  109. id = self.input('id')
  110. info = self.service('common').one('farm', id=id)
  111. if info and info['eros_status'] == 1:
  112. self.out('本地服务已开启,无法通过云端修改农场资料')
  113. return
  114. self.update('farm')
  115. class product_path(Load):
  116. @Web.auth
  117. @Web.setting
  118. def get(self):
  119. self.set(
  120. name = u'产品'
  121. ,path = '/farm/product'
  122. ,width = '600'
  123. ,height = '500'
  124. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'产品名称'))
  125. ,thead = (u'所属农场', u'产品名称', u'图片', u'种植面积', u'平均亩产', u'更新时间')
  126. ,tbody = ('farm','name', 'pic', 'area', 'yields', 'cdate')
  127. ,state = True
  128. )
  129. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  130. self.list('farm_product')
  131. if self.data['list']:
  132. for key, value in enumerate(self.data['list']):
  133. farm = self.service('common').one('farm', id=value['farm_id'])
  134. self.data['list'][key]['farm'] = farm['name']
  135. if self.data['list'][key]['pic']:
  136. self.data['list'][key]['pic'] = '<img src="'+self.data['list'][key]['pic']+'" width="200"/>'
  137. else:
  138. self.data['list'][key]['pic'] = '暂无图片'
  139. self.show('list')
  140. class product_update_path(Load):
  141. @Web.auth
  142. @Web.setting
  143. def get(self):
  144. self.set(
  145. path = '/farm/product'
  146. ,label = (u'所属农场',u'产品名称', u'种植面积', u'平均亩产', u'特点', u'使用须知', u'图片')
  147. ,update = ('farm_id-select-required', 'name-input-required','area-input-required','yields-input-required','charact-input-required','notice-input-required','pic-pic-required')
  148. ,update_farm_id = self.service('common').list('farm', search={'eros_status':2})
  149. )
  150. self.one('farm_product')
  151. self.show('update')
  152. @Web.auth
  153. @Web.setting
  154. def post(self):
  155. #self.data['update']['farm_id'] = farm['id']
  156. self.update('farm_product')
  157. @Web.auth
  158. @Web.setting
  159. def delete(self):
  160. self.drop('farm_product')
  161. class user_path(Load):
  162. @Web.auth
  163. @Web.setting
  164. def get(self):
  165. self.set(
  166. name = u'用户'
  167. ,path = '/farm/user'
  168. ,width = '600'
  169. ,height = '400'
  170. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'用户名称'))
  171. ,thead = (u'所属农场', u'UID', u'用户名称', u'用户手机号', u'更新时间')
  172. ,tbody = ('farm','id', 'username', 'mobile', 'cdate')
  173. ,state = True
  174. )
  175. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  176. self.list('farm_user')
  177. if self.data['list']:
  178. for key, value in enumerate(self.data['list']):
  179. farm = self.service('common').one('farm', id=value['farm_id'])
  180. self.data['list'][key]['farm'] = farm['name']
  181. self.show('list')
  182. class user_update_path(Load):
  183. @Web.auth
  184. @Web.setting
  185. def get(self):
  186. self.set(
  187. path = '/farm/user'
  188. ,label = (u'所属农场',u'账号姓名',u'手机号',u'安全码')
  189. ,update = ('farm_id-select-required','username-input-required','mobile-input-phone','password-password-')
  190. ,update_farm_id = self.service('common').list('farm', search={'eros_status':2})
  191. )
  192. self.one('farm_user')
  193. self.show('update')
  194. @Web.auth
  195. @Web.setting
  196. def post(self):
  197. #self.data['update']['farm_id'] = farm['id']
  198. self.update('farm_user', '手机号已经被注册', mobile=self.data['update']['mobile'])
  199. @Web.auth
  200. @Web.setting
  201. def delete(self):
  202. self.drop('farm_user')