예제 #1
0
def delike(comment_id):
    user = current_user()
    c = Comment.find(comment_id)
    if Comment.check_token():
        c.delike(user.id)
        user.delike_comment(comment_id)
        return redirect(url_for('tweet.detail', tweet_id=c.tweet().id, token=gg.token[user.id]))
예제 #2
0
def update():
    if Comment.check_token():
        form = request.form
        Comment.check_id(form)
        newComment = Comment.update(form)
        # redirect有必要加query吗
        return redirect(url_for('tweet.detail', tweet_id=newComment.tweet_id, token=gg.token[current_user().id]))
예제 #3
0
def update():
    token = request.args.get('token')
    if Comment.check_token(token, gg.csrf_tokens):
        form = request.form
        Comment.check_id(form)
        newTweet = Comment.update(form)
        # redirect有必要加query吗
        return redirect(url_for('tweet.index'))
예제 #4
0
def delete(comment_id):
    u = current_user()
    # comment_id = request.args.get('id', -1)
    # comment_id = int(comment_id)
    token = request.args.get('token')
    if Comment.check_token(token, gg.csrf_tokens):
        c = Comment.find(comment_id)
        if u.id == c.user_id:
            c.remove(comment_id)
        return redirect(url_for('tweet.index'))
예제 #5
0
def add():
    """
    添加comment
    :return: 返回index页面
    """
    user = current_user()
    if Comment.check_token():
        form = request.form
        c = Comment.new(form, user_id=user.id, user_name=user.username)
        return redirect(url_for('tweet.detail', tweet_id=c.tweet_id, token=gg.token[user.id]))
예제 #6
0
def edit(comment_id):
    u = current_user()
    # comment_id = int(request.args.get('id', -1))
    token = request.args.get('token')
    if Comment.check_token(token, gg.csrf_tokens):
        c = Comment.find(comment_id)
        if u.id == c.user_id:
            body = render_template('comment_edit.html',
                            comment_id=c.id,
                            comment_content=c.content, token=token)
            return make_response(body)
        return redirect(url_for('tweet.index'))
예제 #7
0
def add():
    """
    添加comment
    :return: 返回index页面
    """
    user = current_user()
    token = request.args.get('token')
    if Comment.check_token(token, gg.csrf_tokens):
        form = request.form
        c = Comment.new(form, user_id=user.id, user_name=user.username)
        # c.save()
        # uid = c.tweet().user().id
        return redirect(url_for('tweet.index'))
예제 #8
0
def edit(comment_id):
    user = current_user()
    if Comment.check_token():
        c = Comment.find(comment_id)
        Comment.check_id(id=comment_id)
        return render_template('tweet/comment_edit.html', c=c, token=gg.token[user.id], user=user)
예제 #9
0
def delete(comment_id):
    if Comment.check_token():
        c = Comment.find(comment_id)
        Comment.check_id(id=comment_id)
        c.remove(comment_id)
        return redirect(url_for('tweet.detail', tweet_id=c.tweet_id, token=gg.token[current_user().id]))