Beispiel #1
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))
Beispiel #2
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))
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
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)
Beispiel #8
0
def add_comment(user_id, review_id):
	comment = request.form['comment']
	Comment.add_comment(user_id, review_id, comment, 0, 0)
	return redirect(url_for('single_review', review_id=review_id))
Beispiel #9
0
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)