def tweets_and_boards(board_id, current_page): import math if board_id == -1: tweets = Tweet.find_all() else: tweets = Tweet.find_all(board_id=board_id) # 每页显示4个Tweet pages = math.ceil(len(tweets) / 4) if current_page < pages: tweets = tweets[(current_page - 1) * 4:current_page * 4] else: tweets = tweets[(current_page - 1) * 4::] bs = Board.find_all() return tweets, bs, pages
def index(): """ 显示该用户所有tweet :return: 显示tweet页面 """ user_id = int(request.args.get('user_id', -1)) if user_id == -1: u = current_user() user_id = u.id user = User.find(user_id) if user is None: return redirect(url_for('user.login')) else: # 用字典对每个tweet进行token和user.id的匹配 # token = str(uuid.uuid4()) # csrf_tokens[token] = user.id # 保证每次调用index函数时清空gg gg.delete_value() # 保证每次调用index函数时都有新的token可用 gg.set_value(user.id) log('from tweet', gg.csrf_tokens, gg.token) tweets = Tweet.find_all(user_id=user.id, deleted=False) body = render_template('tweet_index.html', tweets=tweets, user=user, token=gg.token) return make_response(body)
def index(request): # 从query取到user_id可以到该用户界面评论 user_id = int(request.query.get('user_id', -1)) if user_id == -1: u = current_user(request) user_id = u.id user = User.find(user_id) if user is None: return redirect('/login') else: tweets = Tweet.find_all(user_id=user.id, deleted=False) body = template('tweet_index.html', tweets=tweets, user=user) return http_response(body)