def newsfeed(): user_id = request.cookies.get(USER_ID) user_id = int(user_id) app.logger.debug('User %d requests news feed', user_id) tweets = tweet_svc.news_feed(user_id) user_name = user_svc.name(user_id) for t in tweets: t['user_name'] = user_name return render_template('twitter.html', title='MaxTurboTwitter', user_name=user_svc.name(user_id), tweets=tweets)
def follows(): from_id = request.cookies.get(USER_ID) from_id = int(from_id) to_id = int(request.form['id_to_follow']) app.logger.debug('User %d requests following user %d', from_id, to_id) if from_id == to_id: return make_response("Invalid followee id {}".format(to_id), 400) done = friend_svc.follows(from_id, to_id) if done: flash('You followed {}'.format(user_svc.name(to_id))) return redirect(url_for('index')) else: # TODO: correct the http status code return make_response( "User {} alread reached max follows".format( user_svc.name(from_id)), 200)
def timeline(): user_id = request.cookies.get(USER_ID) user_id = int(user_id) logging.debug('User %d requests timeline', user_id) followees = friend_svc.followees(user_id) logging.debug('User %d is followed by %d users', user_id, len(followees)) tweets = tweet_svc.timeline(user_id, followees) user_ids = [int(t['user_id']) for t in tweets] user_names = user_svc.names(user_ids) for idx, t in enumerate(tweets): t['user_name'] = user_names[idx] return render_template('twitter.html', title='MaxTurboTwitter', user_name=user_svc.name(user_id), tweets=tweets)