Esempio n. 1
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()
Esempio n. 2
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
Esempio n. 3
0
    a.action = ActionType.FollowProject
    a.created_at = dt.utcnow()

    db.session.add(a)

    success = False
    try:
        db.session.commit()
        success = True
    except Exception, ex:
        db.session.rollback()
        logging.exception(ex)

    if success:
        ProjectFollower.create(project_id=project_id, user_id=current_user.id)
        UserProject.create(project_id=project_id, user_id=current_user.id)


def load_project(slug, current_user):

    project = OpenSourceProject.query.filter_by(slug=slug).first()
    if project is None:
        return

    related_projects = OpenSourceProject.query.filter_by(parent=slug).order_by(
        OpenSourceProject.watchers.desc()).limit(100)

    followers = [f.user_id for f in ProjectFollower.filter(project_id=project.id).limit(20)]
    follower_list = [f for f in user_list_from_ids(followers)]
    print follower_list
Esempio n. 4
0
    if user is None:
        return None

    return load_user(user.id)


def get_user_projects_by_nick(nick):
    try:
        user = CsUser.filter(nick=nick).first()
    except DoesNotExist, dne:
        user = None

    if user is None:
        return

    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()

    return user, os_projects


def load_github_data():
    return
    access_token, config = None

    user = g.get_user("mitsuhiko")
    #TODO: Create a task to fetch all the other information..

    pub_events = user.get_public_events()
Esempio n. 5
0
    a.action = ActionType.FollowProject
    a.created_at = dt.utcnow()

    db.session.add(a)

    success = False
    try:
        db.session.commit()
        success = True
    except Exception, ex:
        db.session.rollback()
        logging.exception(ex)

    if success:
        ProjectFollower.create(project_id=project_id, user_id=current_user.id)
        UserProject.create(project_id=project_id, user_id=current_user.id)


def load_project(slug, current_user):

    project = OpenSourceProject.query.filter_by(slug=slug).first()
    if project is None:
        return

    related_projects = OpenSourceProject.query.filter_by(parent=slug).order_by(
        OpenSourceProject.watchers.desc()).limit(100)

    follower_list = []

    try:
        followers = [