def update(): if Tweet.check_token(): form = request.form Tweet.check_id(form) Tweet.update(form) # todo Tweet update 完成之后 需要到 Tweet 的 index 页面 还是 detail 页面呢? return redirect(url_for('.index'))
def delike(tweet_id): user = current_user() t = Tweet.find(tweet_id) if Tweet.check_token(): t.delike(user.id) user.delike_tweet(tweet_id) return redirect( url_for('.detail', tweet_id=tweet_id, token=gg.token[user.id]))
def update(): token = request.args.get('token') if Tweet.check_token(token, gg.csrf_tokens): form = request.form Tweet.check_id(form) newTweet = Tweet.update(form) # redirect有必要加query吗 return redirect(url_for('.index'))
def edit(tweet_id): user = current_user() if Tweet.check_token(): # tweet_id = int(request.args.get('id', -1)) t = Tweet.find(tweet_id) Tweet.check_id(id=tweet_id) return render_template('tweet/tweet_edit.html', t=t, token=gg.token[user.id], user=user)
def add(): user = current_user() token = request.args.get('token') if Tweet.check_token(token, gg.csrf_tokens): form = request.form t = Tweet.new(form, user_id=user.id, user_name=user.username) # t.user_id = u.id # t.save() # redirect有必要加query吗 # return redirect('/tweet/index?user_id={}'.format(user.id)) return redirect(url_for('.index'))
def edit(tweet_id): u = current_user() token = request.args.get('token') if Tweet.check_token(token, gg.csrf_tokens): # tweet_id = int(request.args.get('id', -1)) t = Tweet.find(tweet_id) if u.id == t.user_id: body = render_template('tweet_edit.html', tweet_id=t.id, tweet_content=t.content, token=token) return make_response(body) return redirect(url_for('.index'))
def delete(tweet_id): u = current_user() # tweet_id = int(request.args.get('id')) token = request.args.get('token') if Tweet.check_token(token, gg.csrf_tokens): # gg.delete_value() # csrf_tokens.pop(token) t = Tweet.find(tweet_id) if u.id == t.user_id: # 这里只是删除了tweet,但是其所拥有的comment的deleted字段变成False t.remove(tweet_id) for c in t.comments(): c.deleted = True c.save() # redirect有必要加query吗 # return redirect('/tweet/index?user_id={}'.format(u.id)) return redirect(url_for('.index'))
def add(): user = current_user() # 这个board_id 是为了跳转index页面而存在,而不是为title和content服务,form里面还应有board_id board_id = int(request.args.get('board_id', -1)) if Tweet.check_token(): form = request.form if form.get('title'): t = Tweet.new(form, user_id=user.id, user_name=user.username) # t.user_id = u.id # t.save() # redirect有必要加query吗 # return redirect('/tweet/index?user_id={}'.format(user.id)) return redirect(url_for('.index', board_id=board_id)) else: bs = Board.find_all() return render_template('tweet/tweet_new.html', token=gg.token[user.id], bs=bs, board_id=board_id, user=user)
def delete(tweet_id): if Tweet.check_token(): t = Tweet.find(tweet_id) Tweet.check_id(id=tweet_id) t.remove_with_comments(tweet_id) return redirect(url_for('.index'))
def new(): token = request.args.get('token') if Tweet.check_token(token, gg.csrf_tokens): body = render_template('tweet_new.html', token=token) return make_response(body)