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))
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))
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))
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))
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))
def topic(topic_id): form = CommentForm() topic = Topic.query.get_or_404(topic_id) topic.click_num += 1 db.session.add(topic) db.session.commit() return render_template('topic/topic.html', topic=topic, form=form)
def single_topic(topic_id): form = CommentForm() topic = Topic.get_topic(topic_id) topic['Time'] = time_diff(topic['Time']) topic['Content'] = topic['Content'].replace('\n', "<div class='text-gap'></div>") comments = Comment.get_comments_by_topic(topic['TopicID']) for c in comments: c['Time'] = time_diff(c['Time']) Topic.add_click_num(topic_id) nodes = Node.get_nodes(16) return render_template('topic/single_topic.html', topic=topic, comments=comments, nodes=nodes, form=form)
def single_topic(topic_id): form = CommentForm() topic = Topic.get_topic(topic_id) topic['Time'] = time_diff(topic['Time']) topic['Content'] = markdown2.markdown(topic['Content']) comments = Comment.get_comments_by_topic(topic['TopicID']) for c in comments: c['Time'] = time_diff(c['Time']) Topic.add_click_num(topic_id) nodes = Node.get_nodes(16) return render_template('single_topic.html', topic=topic, comments=comments, nodes=nodes, form=form)
def work_review(review_id): form = CommentForm() review = WorkReview.query.get_or_404(review_id) # others cannot see draft is_me = True if "user_id" in session and session[ 'user_id'] == review.user_id else False if not is_me and not review.is_publish: abort(404) # Click num + 1 review.click_num += 1 db.session.add(review) db.session.commit() return render_template('work_review/work_review.html', review=review, form=form)
def single_review(review_id): form = CommentForm() # check exist review = Review.get_review(review_id) if not review: abort(404) review['Content'] = markdown2.markdown(review['Content']) review['Time'] = time_diff(review['Time']) Review.add_click_num(review_id) comments = Comment.get_comments_by_review(review_id) for c in comments: c['Time'] = time_diff(c['Time']) return render_template('single_review.html', review=review, comments=comments, form=form)