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 add_comment_to_review(review_id): check_login() 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) # plus comment num by 1 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 build_review_inform_title(replyer_id, review_id): replyer = User.get_user_by_id(replyer_id) review = Review.get_review(review_id) inform_title = "<a href=" + url_for( 'user', user_abbr=replyer['Abbr']) + ">" + replyer[ 'Name'] + "</a> 在评论 " + "<a href=" + url_for( 'single_review', review_id=review_id ) + ">" + review['Title'] + "</a>" + " 中回复了你" return inform_title
def edit_review(review_id): if request.method == 'GET': review = Review.get_review(review_id) return render_template('edit_review.html', review=review) elif request.method == 'POST': title = request.form['title'] content = request.form['content'] Review.edit_review(review_id, title, content) return redirect(url_for('single_review', review_id=review_id))
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)
def edit_review(review_id): review = Review.get_review(review_id) check_private(review['UserID']) if request.method == 'GET': form = ReviewForm(title=review['Title'], content=review['Content']) return render_template('edit_review.html', review=review, form=form) elif request.method == 'POST': form = ReviewForm(request.form) if form.validate(): title = cgi.escape(form.title.data) content = cgi.escape(form.content.data) Review.edit_review(review_id, title, content) return redirect(url_for('single_review', review_id=review_id)) else: return render_template('edit_review.html', review=review, form=form)
def edit_review(review_id): review = Review.get_review(review_id) if review['UserID'] != session['user_id']: abort(404) if request.method == 'GET': form = ReviewForm(title=review['Title'], content=review['Content']) return render_template('review/edit_review.html', review=review, form=form) else: form = ReviewForm(request.form) if form.validate(): title = cgi.escape(form.title.data) content = cgi.escape(form.content.data) is_publish = 1 if 'publish' in request.form else 0 Review.edit_review(review_id, title, content, is_publish) return redirect(url_for('single_review', review_id=review_id)) else: return render_template('review/edit_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) # the others cannot see draft is_me = True if "user_id" in session and session['user_id'] == review['UserID'] else False if not is_me and review['IsPublish'] == 0: 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('review/single_review.html', review=review, comments=comments, form=form)
def delete_review(review_id): review = Review.get_review(review_id) if review['UserID'] != session['user_id']: abort(404) Review.delete(review_id) return redirect(url_for('index'))
def single_review(review_id): review = Review.get_review(review_id) review['Content'] = markdown2.markdown(review['Content']) comments = Comment.get_comments_by_review(review_id) return render_template('single_review.html', review=review, comments=comments)
def build_review_inform_title(replyer_id, review_id): replyer = User.get_user_by_id(replyer_id) review = Review.get_review(review_id) inform_title = "<a href=" + url_for('people', user_abbr=replyer['Abbr']) + ">" + replyer['Name'] + "</a> 在评论 " + "<a href=" + url_for('single_review', review_id=review_id) + ">" + review['Title'] + "</a>" + " 中回复了你" return inform_title