コード例 #1
0
ファイル: views.py プロジェクト: concefly/light
	def get(self):
		req = self.request.arguments.copy()
		with orm.db_session:
			if req.has_key('zaddr') and req.has_key('id'):
				#~ zaddr,id ... 请求
				req_zaddr = int(req.pop('zaddr')[0])
				req_id = int(req.pop('id')[0])
				dev = db.DevVarInfo.get(zaddr=req_zaddr,did=req_id);
				if dev==None:
					InitValue = {}
					InitValue['zaddr'] = req_zaddr
					InitValue['did'] = req_id
					for k in req:
						if k=='name':
							InitValue['name'] = req['name'][0]
						elif k=='describe':
							InitValue['describe'] = req['describe'][0]
					dev = db.DevVarInfo(**InitValue)
				else:
					dev.name = req['name'][0]
					dev.describe = req['describe'][0]
				db.commit()
		with orm.db_session:
			#~ 返回所有记录
			devs = db.DevVarInfo.select()
			res = []
			for dev in devs:
				d = {}
				d['zaddr'] = dev.zaddr
				d['id'] = dev.did
				d['name'] = dev.name
				d['describe'] = dev.describe
				res.append(d)
		self.write(json.dumps(res))
コード例 #2
0
ファイル: views.py プロジェクト: concefly/light
	def get(self):
		req = self.request.arguments.copy()
		req_limit = int(req.pop('limit')[0])
		#~ 
		with orm.db_session:
			if req.has_key('zaddr') and req.has_key('id'):
				#~ 添加记录
				InitValue = {}
				InitValue['zaddr'] = int(req.pop('zaddr')[0])
				InitValue['did'] = int(req.pop('id')[0])
				InitValue['light'] = int(req['light'][0])
				db.DevDyn01(**InitValue)
				db.commit()
				#~ 发送消息
				d = dict(msg='changeDevDyn01')
				d.update(InitValue)
				message.sender.send(d)
		with orm.db_session:
			res = []
			devs = db.DevDyn01.select().order_by(db.desc(db.DevDyn01.time))[:req_limit]
			for dev in devs:
				d = {}
				d['zaddr'] = dev.zaddr
				d['id'] = dev.did
				d['time'] = convertDatetime(dev.time)
				d['light'] = dev.light
				res.append(d)
		self.write(json.dumps(res))
コード例 #3
0
ファイル: views.py プロジェクト: concefly/light
	def get(self):
		req = self.request.arguments.copy()
		with orm.db_session:
			if req.has_key('zaddr'):
				#~ zaddr, ... 请求
				req_zaddr = int(req.pop('zaddr')[0])
				group = db.GroupVarInfo.get(zaddr=req_zaddr);
				if group==None:
					InitValue = {}
					InitValue['zaddr'] = req_zaddr
					for k in req:
						if k=='name':
							InitValue['name'] = req['name'][0]
						elif k=='describe':
							InitValue['describe'] = req['describe'][0]
					group = db.GroupVarInfo(**InitValue)
				else:
					group.name = name=req['name'][0]
					group.describe = name=req['describe'][0]
				db.commit()
			#~ 返回所有记录
		with orm.db_session:
			groups = db.GroupVarInfo.select()
			res = []
			for group in groups:
				d = {}
				d['zaddr'] = group.zaddr
				d['name'] = group.name
				d['describe'] = group.describe
				res.append(d)
		self.write(json.dumps(res))