| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 | 
							- #!/usr/bin/env python
 
- # -*- coding: utf-8 -*-
 
- """
 
-     demeter web page
 
-     name:msg.py 消息相关
 
-     author:rabin
 
- """
 
- from __load__ import *
 
- push = ({'id':'sms', 'name':'短信'}, {'id':'weixin', 'name':'微信'})
 
- class msg_path(Load):
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def get(self):
 
- 		self.common(
 
- 			name = u'消息'
 
- 			,path = '/msg/msg'
 
- 			,width = '600'
 
- 			,height = '600'
 
- 			,add = False
 
- 			,edit = False
 
- 			,full = True
 
- 			,search = (('farm_id-select-','type_id-select-','content-input-mlike'), (u'选择农场',u'硬件类型', u'消息内容'))
 
- 			,thead = (u'所属农场', u'消息类型', u'消息内容', u'是否已读',u'发送时间')
 
- 			,tbody = ('farm','type', 'content', 'status', 'cdate')
 
- 			,state = False
 
- 		)
 
- 		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
 
- 		self.data['common']['search_type_id-select-'] = self.service('common').list('msg_type')
 
- 		self.commonList('msg')
 
- 		if self.data['list']:
 
- 			for key, value in enumerate(self.data['list']):
 
- 				farm = self.service('common').one('farm', id=value['farm_id'])
 
- 				self.data['list'][key]['farm'] = farm['name']
 
- 				htype = self.service('common').one('msg_type', id=value['type_id'])
 
- 				self.data['list'][key]['type'] = htype['name']
 
- 				if value['uid']:
 
- 					user = self.service('common').one('farm_user', id=value['uid'])
 
- 					self.data['list'][key]['user'] = user['username']
 
- 				else:
 
- 					self.data['list'][key]['user'] = '无'
 
- 				if value['status'] == True:
 
- 					self.data['list'][key]['status'] = '已读'
 
- 				else:
 
- 					self.data['list'][key]['device'] = '未读'
 
- 		self.commonView('list')
 
- class msg_update_path(Load):
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def get(self):
 
- 		self.common(
 
- 			path = '/msg/msg'
 
- 			,label = (u'所属农场',u'发送用户',u'消息类型',u'消息内容',u'消息链接',u'推送')
 
- 			,update = ('farm_id-select--uid','uid-checkbox--farm_id','msg_type-select-required','content-editor-required','link-input-','push-checkbox-')
 
- 			,update_msg_type = self.service('common').list('msg_type')
 
- 			,update_farm_id = Demeter.config['setting']['farmList']
 
- 			,update_uid = self.service('common').list('farm_user')
 
- 			,update_push = push
 
- 		)
 
- 		self.commonOne('msg')
 
- 		self.commonView('update')
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def post(self):
 
- 		# 发消息
 
- 		self.commonUpdate('msg')
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def delete(self):
 
- 		self.commonDelete('msg')
 
- class type_path(Load):
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def get(self):
 
- 		self.common(
 
- 			name = u'消息类型'
 
- 			,path = '/msg/type'
 
- 			,width = '600'
 
- 			,height = '300'
 
- 			,search = (('name-input-mlike',), (u'类型名称',))
 
- 			,thead = (u'类型ID', u'类型名称',u'类型key', u'更新时间')
 
- 			,tbody = ('id', 'name', 'key', 'cdate')
 
- 			,state = False
 
- 		)
 
- 		self.commonList('msg_type')
 
- 		self.commonView('list')
 
- class type_update_path(Load):
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def get(self):
 
- 		self.common(
 
- 			path = '/msg/type'
 
- 			#,label = (u'类型名称', u'类型key',u'推送')
 
- 			#,update = ('name-input-required', 'key-input-required','push-checkbox-')
 
- 			,label = (u'类型名称', u'类型key')
 
- 			,update = ('name-input-required', 'key-input-required')
 
- 			,update_push = push
 
- 		)
 
- 		self.commonOne('msg_type')
 
- 		self.commonView('update')
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def post(self):
 
- 		self.commonUpdate('msg_type')
 
- 	@Web.auth
 
- 	@Web.setting
 
- 	def delete(self):
 
- 		self.commonDelete('msg_type')
 
 
  |