farm.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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'农场名称', u'功能列表') #表头
  21. ,tbody = ('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. )
  38. self.commonList('farm')
  39. if self.data['list']:
  40. for key, value in enumerate(self.data['list']):
  41. id = str(value['id'])
  42. param = '?farm=' + id + '&search_farm_id-select-=' + id
  43. self.data['list'][key]['func'] = ''
  44. for i in menu:
  45. self.data['list'][key]['func'] = self.data['list'][key]['func'] + '<a href="'+i['url']+''+param+'">'+i['name']+'</a>&nbsp;&nbsp;&nbsp;&nbsp;'
  46. self.commonView('list')
  47. class farm_update_path(Load):
  48. @Web.auth
  49. @Web.setting
  50. def get(self):
  51. self.common(
  52. path = '/farm/farm'
  53. ,label = (u'农场名称',)
  54. ,update = ('name-input-required',)
  55. )
  56. self.commonOne('farm')
  57. self.commonView('update')
  58. @Web.auth
  59. @Web.setting
  60. def post(self):
  61. id = self.commonUpdate('farm')
  62. Demeter.config['setting']['farmList'] = self.service('common').list('farm')
  63. #self.gateway(id)
  64. def gateway(self, farm):
  65. gateway = self.data['update']['gateway']
  66. if gateway:
  67. #换行隔开,逗号隔开,插入到网关表里
  68. data = gateway.split("\r\n")
  69. for value in data:
  70. if ',' in value:
  71. value = value.split(',')
  72. else:
  73. value[0] = value
  74. value[1] = '网关' + value
  75. info = self.service('common').one('device_gateway', hardware_id=value[0])
  76. if not info:
  77. insert = {}
  78. insert['farm_id'] = farm
  79. insert['name'] = value[1]
  80. insert['hardware_id'] = value[0]
  81. self.service('common').update('device_gateway', None, insert)
  82. else:
  83. update = {}
  84. update['name'] = value[1]
  85. self.service('common').update('device_gateway', info['id'], update)
  86. class info_path(Load):
  87. @Web.auth
  88. @Web.setting
  89. def get(self):
  90. id = str(Demeter.config['setting']['farm'])
  91. param = '?farm=' + id + '&search_farm_id-select-=' + id
  92. self.common(
  93. path = '/farm/info' + param
  94. ,label = (u'农场名称',u'农场图片',u'农场位置',u'联系电话',u'联系地址',u'农场主姓名',u'农场主照片',u'欢迎语',u'农场介绍')
  95. ,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-请输入农场介绍')
  96. )
  97. self.commonOne('farm', id=Demeter.config['setting']['farm'])
  98. self.commonView('set')
  99. @Web.auth
  100. @Web.setting
  101. def post(self):
  102. self.commonUpdate('farm', id=Demeter.config['setting']['farm'])
  103. class product_path(Load):
  104. @Web.auth
  105. @Web.setting
  106. def get(self):
  107. self.common(
  108. name = u'产品'
  109. ,path = '/farm/product'
  110. ,width = '600'
  111. ,height = '500'
  112. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'产品名称'))
  113. ,thead = (u'所属农场', u'产品名称', u'图片', u'种植面积', u'平均亩产', u'更新时间')
  114. ,tbody = ('farm','name', 'pic', 'area', 'yields', 'cdate')
  115. ,state = True
  116. )
  117. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  118. self.commonList('farm_product')
  119. if self.data['list']:
  120. for key, value in enumerate(self.data['list']):
  121. farm = self.service('common').one('farm', id=value['farm_id'])
  122. self.data['list'][key]['farm'] = farm['name']
  123. if self.data['list'][key]['pic']:
  124. self.data['list'][key]['pic'] = '<img src="'+self.data['list'][key]['pic']+'" width="200"/>'
  125. else:
  126. self.data['list'][key]['pic'] = '暂无图片'
  127. self.commonView('list')
  128. class product_update_path(Load):
  129. @Web.auth
  130. @Web.setting
  131. def get(self):
  132. self.common(
  133. path = '/farm/product'
  134. ,label = (u'所属农场',u'产品名称', u'种植面积', u'平均亩产', u'特点', u'使用须知', u'图片')
  135. ,update = ('farm_id-select-required', 'name-input-required','area-input-required','yields-input-required','charact-input-required','notice-input-required','pic-pic-required')
  136. ,update_farm_id = Demeter.config['setting']['farmList']
  137. )
  138. self.commonOne('farm_product')
  139. self.commonView('update')
  140. @Web.auth
  141. @Web.setting
  142. def post(self):
  143. self.commonUpdate('farm_product')
  144. @Web.auth
  145. @Web.setting
  146. def delete(self):
  147. self.commonDelete('farm_product')
  148. class user_path(Load):
  149. @Web.auth
  150. @Web.setting
  151. def get(self):
  152. self.common(
  153. name = u'用户'
  154. ,path = '/farm/user'
  155. ,width = '600'
  156. ,height = '400'
  157. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'用户名称'))
  158. ,thead = (u'所属农场', u'UID', u'用户名称', u'用户手机号', u'更新时间')
  159. ,tbody = ('farm','id', 'username', 'mobile', 'cdate')
  160. ,state = True
  161. )
  162. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  163. self.commonList('farm_user')
  164. if self.data['list']:
  165. for key, value in enumerate(self.data['list']):
  166. farm = self.service('common').one('farm', id=value['farm_id'])
  167. self.data['list'][key]['farm'] = farm['name']
  168. self.commonView('list')
  169. class user_update_path(Load):
  170. @Web.auth
  171. @Web.setting
  172. def get(self):
  173. self.common(
  174. path = '/farm/user'
  175. ,label = (u'所属农场',u'账号姓名',u'手机号',u'安全码')
  176. ,update = ('farm_id-select-required','username-input-required','mobile-input-phone','password-password-')
  177. ,update_farm_id = Demeter.config['setting']['farmList']
  178. )
  179. self.commonOne('farm_user')
  180. self.commonView('update')
  181. @Web.auth
  182. @Web.setting
  183. def post(self):
  184. self.commonUpdate('farm_user', '手机号已经被注册', mobile=self.data['update']['mobile'])
  185. @Web.auth
  186. @Web.setting
  187. def delete(self):
  188. self.commonDelete('farm_user')