コード例 #1
0
ファイル: logic_user.py プロジェクト: xiaoguangjj/motiky
def is_following_user(uid,uid_to):
    if type(uid_to) == types.IntType:
        _count = db.session.query(UserFollowAsso.id).\
                filter(db.and_(UserFollowAsso.user_id == uid,UserFollowAsso.user_id_to == uid_to)).count()
        return True if _count > 0 else False
    elif type(uid_to) == types.ListType:
        follow_uids = db.session.query(UserFollowAsso.user_id_to).\
                filter(db.and_(UserFollowAsso.user_id == uid,UserFollowAsso.user_id_to.in_(uid_to))).all()
        follow_uids = [u[0] for u in follow_uids]
        ret_list = [(ret,ret in follow_uids) for ret in uid_to]
        return dict(ret_list)
コード例 #2
0
def is_like_post(uid, post_id):
    if type(post_id) == types.IntType:
        _count = db.session.query(UserLikeAsso.id).\
                filter(db.and_(UserLikeAsso.user_id == uid,
                    UserLikeAsso.post_id == post_id)).count()
        return True if _count > 0 else False
    elif type(post_id) == types.ListType:
        liked_post_ids = db.session.query(UserLikeAsso.post_id).\
                filter(db.and_(UserLikeAsso.user_id == uid,
                    UserLikeAsso.post_id.in_(post_id))).all()
        liked_post_ids = [p[0] for p in liked_post_ids]
        ret_list = [(ret, ret in liked_post_ids) for ret in post_id]
        return dict(ret_list)
コード例 #3
0
ファイル: logic_post.py プロジェクト: Letbeauty/motiky
def is_like_post(uid,post_id):
    if type(post_id) == types.IntType:
        _count = db.session.query(UserLikeAsso.id).\
                filter(db.and_(UserLikeAsso.user_id == uid,
                    UserLikeAsso.post_id == post_id)).count()
        return True if _count > 0 else False
    elif type(post_id) == types.ListType:
        liked_post_ids = db.session.query(UserLikeAsso.post_id).\
                filter(db.and_(UserLikeAsso.user_id == uid,
                    UserLikeAsso.post_id.in_(post_id))).all()
        liked_post_ids = [p[0] for p in liked_post_ids]
        ret_list = [(ret,ret in liked_post_ids) for ret in post_id]
        return dict(ret_list)
コード例 #4
0
ファイル: logic_user.py プロジェクト: xiaoguangjj/motiky
def unfollow_user(fid,tid):
    assert_error(all([type(_id) == types.IntType for _id in [fid,tid]]),'ParamError')
    asso = UserFollowAsso.query.filter(db.and_(UserFollowAsso.user_id==fid,UserFollowAsso.user_id_to==tid)).\
            first()
    if asso is None:
        return
    try:
        db.session.delete(asso)
        db.session.commit()
    except:
        db.session.rollback()
        raise
    else:
        return True