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)
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)
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]
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
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
def get_post_item_count(post_id): count = Item.query.filter(db.and_(Item.post_id == post_id,Item.show == True)).count() return count
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]
def get_post_item_count(post_id): count = Item.query.filter(db.and_(Item.post_id == post_id, Item.show == True)).count() return count