Beispiel #1
0
def is_follow_user(uid,uid_to):
    if type(uid_to) == types.IntType:
        is_followed = db.session.query(UserFollowAsso.id).\
                filter(db.and_(UserFollowAsso.user_id == uid,UserFollowAsso.user_id_to == uid_to)).first()
        return False if is_followed is None else True
    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)
Beispiel #2
0
def is_follow_user(uid, uid_to):
    if type(uid_to) == types.IntType:
        is_followed = db.session.query(UserFollowAsso.id).\
                filter(db.and_(UserFollowAsso.user_id == uid,UserFollowAsso.user_id_to == uid_to)).first()
        return False if is_followed is None else True
    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)
Beispiel #3
0
def get_post_item(post_id, limit=50, offset=0):
    items = (
        Item.query.filter(db.and_(Item.post_id == post_id, Item.show == True))
        .order_by(Item.date_create)
        .limit(limit)
        .offset(offset)
        .all()
    )
    return [i.json for i in items]
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
def get_post_item_count(post_id):
    count = Item.query.filter(db.and_(Item.post_id == post_id,Item.show == True)).count()
    return count
Beispiel #7
0
def get_post_item(post_id,limit=50,offset=0):
    items = Item.query.filter(db.and_(Item.post_id == post_id,Item.show == True)).\
            order_by(Item.date_create).limit(limit).offset(offset).all()
    return [i.json for i in items]
Beispiel #8
0
def get_post_item_count(post_id):
    count = Item.query.filter(db.and_(Item.post_id == post_id, Item.show == True)).count()
    return count