def GET(self, channel_uuid): '''返回指定channel下有哪些session ''' try: ucm_self = db_session_mem.query(Ucm_)\ .filter(Ucm_.channel_uuid==channel_uuid)\ .filter(Ucm_.session_id==session.session_id)\ .one() except NoResultFound: pass else: db_api.ucm_update(ucm_self.id, {'atime':datetime.datetime.now()}) ucms = db_api.ucm_get_with_channel(channel_uuid) d = {'ucms':[]} for ucm in ucms: now = datetime.datetime.now() print 'atime:', (now - ucm.atime).seconds if (now - ucm.atime).seconds >= conf.ucm_expire: db_session_mem.delete(ucm) db_session_mem.commit() else: d['ucms'].append({ 'session_id':ucm.session_id, 'nickname':ucm.nickname, }) print d web.header("Content-Type", "application/json") return json.dumps(d)
def ucm_create(values): #values = {session_id, nickname, channel} ucm = User_channel_map() ucm.update(values) session_mem.add(ucm) session_mem.commit() return ucm
def ucm_update(ucm_id, values): ucm = session_mem.query(User_channel_map).filter(User_channel_map.id==ucm_id).one() ucm.update(values) session_mem.commit() return ucm