Exemplo n.º 1
0
def add_comment_to_review(review_id):
    form = CommentForm(request.form)
    if form.validate():
        comment = cgi.escape(form.comment.data)

        # add comment
        replyer_id = session['user_id']
        replyee_id = get_comment_replyee_id(comment)    # check if @people exist
        if replyee_id != -1:
            comment = rebuild_comment(comment, replyee_id)
        new_comment_id = Comment.add_comment_to_review(review_id, replyer_id, comment)

        Review.add_comment_num(review_id)

        # add inform
        review_user_id = Review.get_review(review_id)['UserID']
        inform_title = build_review_inform_title(replyer_id, review_id)
        # if the review not add by me
        if  replyer_id != review_user_id:
            Inform.add(replyer_id, review_user_id, inform_title, comment)
        # if replyee exist,
        # and the topic not add by me,
        # and not review_user_id, because if so, the inform has already been sended above
        if replyee_id != -1 and replyee_id != replyer_id and replyee_id != review_user_id:
            Inform.add(replyer_id, replyee_id, inform_title, comment)
        return redirect(url_for('single_review', review_id=review_id) + "#" + str(new_comment_id))
    else:
        return redirect(url_for('single_review', review_id=review_id))
Exemplo n.º 2
0
def add_comment_to_topic(topic_id):
    form = CommentForm(request.form)    
    if form.validate():
        comment = cgi.escape(form.comment.data)

        # add comment
        replyer_id = session['user_id']
        replyee_id = get_comment_replyee_id(comment)    # check if @people exist
        if replyee_id != -1:
            comment = rebuild_comment(comment, replyee_id)
        new_comment_id = Comment.add_comment_to_topic(topic_id, replyer_id, comment)

        # plus comment num by 1
        Topic.add_comment_num(topic_id)

        # add inform
        topic_user_id = Topic.get_topic(topic_id)['UserID']
        inform_title = build_topic_inform_title(replyer_id, topic_id)
        # if the topic not add by me
        if replyer_id != topic_user_id:
            Inform.add(replyer_id, topic_user_id, inform_title, comment)
        # if replyee exist,
        # and the topic not add by me,
        # and not topic_user_id, because if so, the inform has already been sended above
        if replyee_id != -1 and  replyee_id != replyer_id and replyee_id != topic_user_id:
            Inform.add(replyer_id, replyee_id, inform_title, comment)
        return redirect(url_for('single_topic', topic_id=topic_id) + "#" + str(new_comment_id))
    else:
        return redirect(url_for('single_topic', topic_id=topic_id))
Exemplo n.º 3
0
def comment_work_review(review_id):
    form = CommentForm(request.form)
    if form.validate():
        comment = WorkReviewComment(content=cgi.escape(form.content.data), review_id=review_id, user_id=session['user_id'])
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('work_review', review_id=review_id) + "#" + str(comment.id))
    else:
        return redirect(url_for('work_review', review_id=review_id))
Exemplo n.º 4
0
def comment_topic(topic_id):
    form = CommentForm(request.form)
    if form.validate():
        comment = TopicComment(content=cgi.escape(form.content.data),
                               topic_id=topic_id,
                               user_id=session['user_id'])
        db.session.add(comment)
        db.session.commit()
        return redirect(
            url_for('topic', topic_id=topic_id) + "#" + str(comment.id))
    else:
        return redirect(url_for('topic', topic_id=topic_id))
Exemplo n.º 5
0
def comment_review(review_id):
    form = CommentForm(request.form)
    if form.validate():
        comment = WorkReviewComment(content=cgi.escape(form.content.data),
                                    review_id=review_id,
                                    user_id=session['user_id'])
        db.session.add(comment)
        db.session.commit()
        return redirect(
            url_for('review', review_id=review_id) + "#" + str(comment.id))
    else:
        return redirect(url_for('review', review_id=review_id))