farm.py 6.6 KB

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