示例#1
0
def load_user(user_id, current_user=None):
    """
    Loads all the details about the user including Followers/Following/OpenSource projects list.
    """
    if user_id is None:
        return None

    logging.warn("Loading user {}".format(user_id))
    user = User.query.get(user_id)

    user_followers, user_following = [], []

    # FIXME: This try/except block is ugly as hell. Refactor please!
    try:
        followers = [
            f.follower_id
            for f in UserFollower.filter(user_id=user_id).limit(20)
        ]
        following = [
            f.following_id
            for f in UserFollowing.filter(user_id=user_id).limit(20)
        ]

        cassa_users = user_list_from_ids(set(followers + following), dict=True)

        def expand(o):
            extras = o.extended
            dict_val = o._as_dict()
            dict_val.update(**extras)
            return dict_val

        user_followers = [
            filter(lambda x: x.get('id') == u, cassa_users)[0]
            for u in followers
        ]
        user_following = [
            filter(lambda x: x.get('id') == u, cassa_users)[0]
            for u in following
        ]

    except Exception, ex:
        logging.warn(ex)
        sentry_client.captureException()
示例#2
0
def load_user(user_id, current_user=None):
    logging.warn("Loading user {}".format(user_id))
    user = User.query.get(user_id)

    user_followers, user_following, os_projects = [], [], []

    # FIXME: This try/except block is ugly as hell. Refactor please!
    try:
        followers = [
            f.follower_id
            for f in UserFollower.filter(user_id=user_id).limit(20)
        ]
        following = [
            f.following_id
            for f in UserFollowing.filter(user_id=user_id).limit(20)
        ]

        projects = [p.project_id for p in UserProject.filter(user_id=user_id)]
        os_projects = OpenSourceProject.query.filter(
            OpenSourceProject.id.in_(projects)).order_by(
                OpenSourceProject.stars.desc()).all()
        cassa_users = user_list_from_ids(set(followers + following), dict=True)

        def expand(o):
            extras = o.extended
            dict_val = o._as_dict()
            dict_val.update(**extras)
            return dict_val

        user_followers = [
            filter(lambda x: x.get('id') == u, cassa_users)[0]
            for u in followers
        ]
        user_following = [
            filter(lambda x: x.get('id') == u, cassa_users)[0]
            for u in following
        ]

    except Exception, ex:
        logging.warn(ex)
        sentry_client.captureException()
示例#3
0
def load_user(user_id):
    logging.warn("Loading user {}".format(user_id))
    user = User.query.get(user_id)
    followers = [f.follower_id for f in UserFollower.filter(user_id=user_id).limit(20)]
    following = [f.following_id for f in UserFollowing.filter(user_id=user_id).limit(20)]

    projects = [p.project_id for p in UserProject.filter(user_id=user_id)]
    os_projects = OpenSourceProject.query.filter(OpenSourceProject.id.in_(projects)).all()
    cassa_users = user_list_from_ids(set(followers+following), dict=True)

    #print [user for user in csUsers]

    def expand(o):
        #d = o._as_dict()
        #d = d.update(d.get('extended'))
        extras = o.extended
        dict_val = o._as_dict()
        dict_val.update(**extras)
        return dict_val

    user_followers = [filter(lambda x: x.get('id') == user, cassa_users)[0] for user in followers]
    user_following = [filter(lambda x: x.get('id') == user, cassa_users)[0] for user in following]

    return user, user_followers, user_following, os_projects
示例#4
0
        return False

    a = Action()
    a.from_id = current_user.id
    a.to_id = user_id
    a.action = ActionType.FollowUser
    db.session.add(a)
    success = False
    try:
        db.session.commit()
        success = True
    except Exception,ex :
        db.session.rollback()

    if success:
        UserFollower.create(user_id=user_id,follower_id=current_user.id)
        UserFollowing.create(user_id=current_user.id, following_id=user_id)

    return success


def user_list_from_ids(ids, dict=True):
    temp_user = CsUser.filter(CsUser.id.in_(set(ids))).limit(50)

    if dict:
        user_list = []
        for u in temp_user:
            d = u._as_dict()
            extras = u.extended
            d.update(**extras)
            user_list.append(d)
示例#5
0
        return False

    a = Action()
    a.from_id = current_user.id
    a.to_id = user_id
    a.action = ActionType.FollowUser
    db.session.add(a)
    success = False
    try:
        db.session.commit()
        success = True
    except Exception, ex:
        db.session.rollback()

    if success:
        UserFollower.create(user_id=user_id, follower_id=current_user.id)
        UserFollowing.create(user_id=current_user.id, following_id=user_id)

    return success


def user_list_from_ids(ids, dict=True):
    temp_user = CsUser.filter(CsUser.id.in_(set(ids))).limit(50)

    if dict:
        user_list = []
        for u in temp_user:
            d = u._as_dict()
            extras = u.extended
            d.update(**extras)
            user_list.append(d)