farm.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. ,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':'/device/gateway'}
  26. ,{'name':'设备管理', 'url':'/device/info'}
  27. ,{'name':'农事管理', 'url':'/work/work'}
  28. ,{'name':'农事分类', 'url':'/work/category'}
  29. ,{'name':'地块管理', 'url':'/work/land'}
  30. ,{'name':'批次管理', 'url':'/origin/batch'}
  31. ,{'name':'用户管理', 'url':'/farm/user'}
  32. ,{'name':'打印机管理', 'url':'/device/printer'}
  33. ,{'name':'消息提醒', 'url':'/msg/msg'}
  34. )
  35. self.commonList('farm')
  36. if self.data['list']:
  37. for key, value in enumerate(self.data['list']):
  38. id = str(value['id'])
  39. param = '?farm=' + id + '&search_farm_id-select-=' + id
  40. self.data['list'][key]['func'] = ''
  41. for i in menu:
  42. self.data['list'][key]['func'] = self.data['list'][key]['func'] + '<a href="'+i['url']+''+param+'">'+i['name']+'</a>&nbsp;&nbsp;&nbsp;&nbsp;'
  43. self.commonView('list')
  44. class farm_update_path(Load):
  45. @Web.auth
  46. @Web.setting
  47. def get(self):
  48. self.common(
  49. path = '/farm/farm'
  50. ,label = (u'农场名称',u'农场地址',u'联系人',u'联系电话')
  51. ,update = ('name-input-required','address-input-required','master_name-input-required','tel-input-required')
  52. )
  53. self.commonOne('farm')
  54. self.commonView('update')
  55. @Web.auth
  56. @Web.setting
  57. def post(self):
  58. id = self.commonUpdate('farm')
  59. Demeter.config['setting']['farmList'] = self.service('common').list('farm')
  60. class info_path(Load):
  61. @Web.auth
  62. @Web.setting
  63. def get(self):
  64. id = str(Demeter.config['setting']['farm'])
  65. param = '?farm=' + id + '&search_farm_id-select-=' + id
  66. self.common(
  67. path = '/farm/info' + param
  68. ,label = (u'农场名称',u'农场图片',u'联系电话',u'农场地址',u'联系人',u'农场介绍')
  69. ,update = ('name-input-required','pic-pic-required-1000px*300~450px','tel-input-required','address-input-required','master_name-input-required',u'info-text-required-请输入农场介绍')
  70. )
  71. self.commonOne('farm', id=Demeter.config['setting']['farm'])
  72. self.commonView('set')
  73. @Web.auth
  74. @Web.setting
  75. def post(self):
  76. self.commonUpdate('farm', id=Demeter.config['setting']['farm'])
  77. class user_path(Load):
  78. @Web.auth
  79. @Web.setting
  80. def get(self):
  81. self.common(
  82. name = u'用户'
  83. ,path = '/farm/user'
  84. ,width = '600'
  85. ,height = '400'
  86. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'用户名称'))
  87. ,thead = (u'所属农场', u'用户名称', u'绑定列表', u'用户手机号', u'更新时间')
  88. ,tbody = ('farm','username','wechat', 'mobile', 'cdate')
  89. ,state = True
  90. )
  91. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  92. self.commonList('farm_user')
  93. if self.data['list']:
  94. for key, value in enumerate(self.data['list']):
  95. farm = self.service('common').one('farm', id=value['farm_id'])
  96. id = str(farm['id'])
  97. self.data['list'][key]['farm'] = farm['name']
  98. param = '?farm=' + id + '&search_uid-input-=' + str(value['id'])
  99. self.data['list'][key]['wechat'] = '<a href="/farm/user_wechat'+param+'">点此查看</a>'
  100. self.commonView('list')
  101. class user_update_path(Load):
  102. @Web.auth
  103. @Web.setting
  104. def get(self):
  105. self.common(
  106. path = '/farm/user'
  107. ,label = (u'所属农场',u'账号姓名',u'手机号',u'安全码')
  108. ,update = ('farm_id-select-required','username-input-required','mobile-input-phone','password-password-')
  109. ,update_farm_id = Demeter.config['setting']['farmList']
  110. )
  111. self.commonOne('farm_user')
  112. self.commonView('update')
  113. @Web.auth
  114. @Web.setting
  115. def post(self):
  116. self.commonUpdate('farm_user', '手机号已经被注册', mobile=self.data['update']['mobile'])
  117. @Web.auth
  118. @Web.setting
  119. def delete(self):
  120. self.commonDelete('farm_user')
  121. class user_wechat_path(Load):
  122. @Web.auth
  123. @Web.setting
  124. def get(self):
  125. self.common(
  126. name = u'微信绑定列表'
  127. ,path = '/farm/user_wechat'
  128. ,width = '600'
  129. ,height = '400'
  130. ,add = False
  131. ,edit = False
  132. ,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','uid-input-'), (u'日期范围',u'开始时间',u'截止时间','选择农场',u'用户id'))
  133. ,thead = (u'所属农场', u'微信昵称', u'微信openid', u'更新时间', u'封禁')
  134. ,tbody = ('farm','nickname','openid', 'cdate', 'ban')
  135. ,state = False
  136. )
  137. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  138. self.commonList('farm_user_wechat')
  139. if self.data['list']:
  140. for key, value in enumerate(self.data['list']):
  141. farm = self.service('common').one('farm', id=value['farm_id'])
  142. self.data['list'][key]['farm'] = farm['name']
  143. if value['status'] == True:
  144. self.data['list'][key]['ban'] = '<a href="javascript:;" alt="点此恢复" onclick="oper(this,\''+value['id']+'\', \'/farm/user_wechat_update\', \'False\')">已封禁</a>'
  145. else:
  146. self.data['list'][key]['ban'] = '<a href="javascript:;" alt="点此封禁" onclick="oper(this,\''+value['id']+'\', \'/farm/user_wechat_update\', \'True\')">封禁</a>'
  147. self.commonView('list')
  148. class user_wechat_update_path(Load):
  149. @Web.auth
  150. @Web.setting
  151. def get(self):
  152. self.common(
  153. path = '/farm/user_wechat'
  154. ,label = (u'微信昵称',)
  155. ,update = ('nickname-input-required',)
  156. ,update_farm_id = Demeter.config['setting']['farmList']
  157. )
  158. self.commonOne('farm_user_wechat')
  159. self.commonView('update')
  160. @Web.auth
  161. @Web.setting
  162. def post(self):
  163. self.commonUpdate('farm_user_wechat')
  164. @Web.auth
  165. @Web.setting
  166. def delete(self):
  167. id = self.input('id')
  168. update = {}
  169. update['status'] = self.input('status', True)
  170. self.service('common').update('farm_user_wechat', id, update)
  171. #self.commonDelete('farm_user_wechat')