Beispiel #1
0
    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)
Beispiel #2
0
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
Beispiel #3
0
def ucm_get_with_channel(channel_uuid):
    return session_mem.query(User_channel_map).filter(User_channel_map.channel_uuid==channel_uuid).all()
Beispiel #4
0
def ucm_get_with_session(session_id):
    return session_mem.query(User_channel_map).filter(User_channel_map.session_id==session_id).all()
Beispiel #5
0
def ucm_count(session_id, channel_uuid):
    count = session_mem.query(User_channel_map).\
            filter(User_channel_map.session_id==session_id).\
            filter(User_channel_map.channel_uuid==channel_uuid).count()
    return count