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