Пример #1
0
def run(**kwargs):
    if not kwargs:
        return Res(errno=3,error="not value")
    uexd=UserExData.objects(uid=BackEndEnvData.uid).first()
    if uexd is None:
        uexd=UserExData()
        uexd.uid=BackEndEnvData.uid
    uexd.client_data.update(kwargs)
    uexd.save()
    return Res()
Пример #2
0
def run(uid):
    if isinstance(uid,list)==False:
        uid=[uid]
    with dbconfig.Session() as session:
        userexdatalist=UserExData.objects(uid__in=uid)
        userexinfo={}
        for exinfo in userexdatalist:
            userexinfo[exinfo.uid]=exinfo.toJson()
        users_circle=session.query(UserCircle,CircleRole,CircleDef)\
            .join(CircleRole,and_(CircleRole.cid==UserCircle.cid,CircleRole.roleid==UserCircle.roleid))\
            .join(CircleDef,CircleDef.cid==UserCircle.cid)\
            .filter(UserCircle.uid.in_(uid)).all()
        circles={}
        for uc,cr,cd in users_circle:
            ll=circles.get(uc.uid,[])
            linedata=uc.toJson()
            del linedata['uid']
            linedata.update(cr.toJson())
            linedata.update(cd.toJson())
            ll.append(linedata)
            circles[uc.uid]=ll

        users=session.query(User).filter(User.uid.in_(uid)).all()
        ulist=[]
        for user in users:
            uinfo=user.toJson()
            uinfo['exinfo']=userexinfo.get(user.uid,None)
            uinfo['circle']=circles.get(user.uid,None)
            ulist.append(uinfo)
    return Res({"users":ulist})
Пример #3
0
def run(uids):
    if isinstance(uids,list)==False:
        uids=[uids]
    ulist=[]
    for exdata in UserExData.objects(uid__in=uids):
        ulist.append({"uid":exdata.uid,"tags":exdata.tags})
    return Res({"tags":ulist})
Пример #4
0
def GetUserInfo(uid):
    session=dbconfig.ReadSession()
    with helper.AutoClose(session) as autoclose:
        userexdata=UserExData.objects(uid=uid).first()
        users_circle=session.query(UserCircle,CircleRole,CircleDef)\
            .join(CircleRole,and_(CircleRole.cid==UserCircle.cid,CircleRole.roleid==UserCircle.roleid))\
            .join(CircleDef,CircleDef.cid==UserCircle.cid)\
            .filter(UserCircle.uid==uid).all()
        circles=[]
        for uc,cr,cd in users_circle:
            linedata=uc.toJson()
            del linedata['uid']
            linedata.update(cr.toJson())
            linedata.update(cd.toJson())
            circles.append(linedata)

        user=session.query(User).filter(User.uid==uid).first()

        user_endorsinfo=session.query(EndorsementInfo).filter(EndorsementInfo.uid==uid).first()

        user_endors=[]
        for epair in session.query(Endorsement).filter(Endorsement.uid==uid).all():
            user_endors.append({'slogan':epair.slogan,'create_time':epair.create_time,'merchandise':GetMerchandise(epair.mid)})

        resultobj={"user":user.toJson()}
        if userexdata is not None:
            resultobj['exdata']=userexdata.toJson()
        if circles:
            resultobj['circles']=circles
        if user_endorsinfo:
            resultobj['endorsement']=user_endorsinfo.toJson()
        if user_endors:
            resultobj['endors_list']=user_endors
    return resultobj
Пример #5
0
def run(long,lat):
    with dbconfig.Session() as session:
        ulist=[]

        for user in UserExData.objects(position__geo_within_sphere=[(long,lat),SEARCH_R]).only('uid','position','update_time'):
            ulist.append({"uid":user.uid,
                "lat":user.position['coordinates'][1],
                "long":user.position['coordinates'][0],
                "time":user.update_time})
        return Res({"users":ulist})
Пример #6
0
def run(alltag,lat=None,long=None):
    findparams=Q(tags__all=alltag)
    if lat is not None and long is not None:
        findparams=findparams and Q(position__geo_within_sphere=[(long,lat),SEARCH_R])
    ulist=[]
    for user in UserExData.objects(findparams).order_by('-update_time').limit(300):
        onedata={"uid":user.uid,"tags":user.tags}
        if user.position:
            onedata["lat"]=user.position['coordinates'][1]
            onedata["long"]=user.position['coordinates'][0]
            onedata['time']=user.update_time
        ulist.append(onedata)
    return Res({'users':ulist})
Пример #7
0
from datamodel.user import UserExData, UserLikeLog
from tools.helper import Res
from tools.session import CheckSession

__author__ = 'amen'
import BackEndEnvData
import dbconfig


@CheckSession()
def run(uid):
    if uid==BackEndEnvData.uid:
        return Res(errno=2,error="like self")
    with dbconfig.Session() as session:
        new_like=UserLikeLog()
        new_like.uid=uid
        new_like.by_uid=BackEndEnvData.uid
        session.add(new_like)
        try:
            session.commit()
        except Exception,e:
            return Res(errno=2,error="has liked")
    UserExData.objects(uid=uid).update_one(upsert=True, inc__like_me_count=1)
    return Res()
Пример #8
0
def run(tags):
    if isinstance(tags,list)==False:
        return Res(errno=2,error="value type error")
    tags=list(set(tags))
    UserExData.objects(uid=BackEndEnvData.uid).update_one(upsert=True,set__tags=tags)
    return Res()
Пример #9
0
def run(long,lat):
    UserExData.objects(uid=BackEndEnvData.uid).update_one(upsert=True,set__position=[long,lat],set__update_time=datetime.datetime.now())
    return Res()
Пример #10
0
def run(sessionid):
    if BackEndEnvData.uid is None:
        data=dbconfig.redisdb.get(str('session:%s'%sessionid))
        if data is None:
            return {"errno":1,"error":"session not found","result":{}}
        data=json.loads(data)
        be_uid=int(data['uid'])
    else:
        be_uid=BackEndEnvData.uid
    beinvitelist=[]
    with dbconfig.Session() as session:
        user_data=session.query(User).filter(User.uid==be_uid).first()
        new_user=not user_data.nick
        session.execute(text('delete from connection_info where uid=:uid or (queue_id=:queue_id and connection_id=:connection_id);'+
                    'insert into connection_info(uid,queue_id,connection_id) values(:uid,:queue_id,:connection_id);'),
                             {"uid":user_data.uid,"queue_id":BackEndEnvData.reply_queue,"connection_id":BackEndEnvData.connection_id})
        session.commit()

        if new_user:
            eventpost=[]
            for one in list(UserInviteLog.objects(phone=user_data.phone).order_by('-invite_id')):
                one.joined_uid=user_data.uid
                one.save()
                if one.join_cid and one.join_roleid:
                    usercircle=UserCircle()
                    usercircle.uid=user_data.uid
                    usercircle.by_uid=one.uid
                    usercircle.cid=one.join_cid
                    usercircle.roleid=one.join_roleid
                    session.merge(usercircle)

                friend=FriendList()
                friend.uid=user_data.uid
                friend.friendid=one.uid
                friend.type=2
                session.merge(friend)

                friend=FriendList()
                friend.uid=one.uid
                friend.friendid=user_data.uid
                friend.type=3
                session.merge(friend)

                event=Events()
                event.touid=one.uid
                event.param1=user_data.uid
                event.param2=3
                event.type="add_friend"
                event=session.merge(event)
                eventpost.append(event)

                beinvitelist.append(one.toJson())
            session.commit()
            if beinvitelist:
                inviteinfo=beinvitelist[0]
                user_data.nick=inviteinfo['nick']
                user_data.headpic=inviteinfo['headpic']
                user_data.sex=inviteinfo['sex']
                user_data.birthday=inviteinfo['birthday']
                user_data.marriage=inviteinfo['marriage']
                user_data.height=inviteinfo['height']
                user_data.position=inviteinfo['position']
                user_data=session.merge(user_data)
                session.commit()
            for one in eventpost:
                AddEventNotify(one)

        uexd=UserExData.objects(uid=BackEndEnvData.uid).first()
        resultdata={"user":user_data.toJson()}
        if uexd:
            resultdata['client_data']=uexd.client_data
        if beinvitelist:
            resultdata['invite_list']=beinvitelist
        einfo=session.query(EndorsementInfo).filter(EndorsementInfo.uid==user_data.uid).first()
        if einfo:
            resultdata['endorsement']=einfo.toJson()
        return Res(resultdata)
Пример #11
0
def run():
    uexd=UserExData.objects(uid=BackEndEnvData.uid).first()
    if uexd is None:
        return Res()
    else:
        return Res(uexd.client_data)