farm.py 6.9 KB

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