Пример #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))
Пример #2
0
def edit_topic(topic_id):
    # auth check
    topic = Topic.get_topic(topic_id)
    check_private(topic['UserID'])

    node_types = Node.get_types()
    for nt in node_types:
        nt['nodes'] = Node.get_nodes_by_type(nt['TypeID'])

    if request.method == 'GET':
        form = TopicForm(node_id=topic['NodeID'],
                         title=topic['Title'],
                         content=topic['Content'])
        return render_template('edit_topic.html',
                               topic=topic,
                               node_types=node_types,
                               form=form)
    elif request.method == 'POST':
        form = TopicForm(request.form)
        if form.validate():
            node_id = int(form.node_id.data)
            title = cgi.escape(form.title.data)
            content = cgi.escape(form.content.data)
            new_topic_id = Topic.edit(topic_id, node_id, title, content)
            return redirect(url_for('single_topic', topic_id=topic_id))
        else:
            return render_template('edit_topic.html',
                                   topic=topic,
                                   node_types=node_types,
                                   form=form)
Пример #3
0
def build_topic_inform_title(replyer_id, topic_id):
    replyer = User.get_user_by_id(replyer_id)
    topic = Topic.get_topic(topic_id)
    inform_title = "<a href=" + url_for(
        'user', user_abbr=replyer['Abbr']) + ">" + replyer[
            'Name'] + "</a>&nbsp;&nbsp;在话题&nbsp;&nbsp;" + "<a href=" + url_for(
                'single_topic', topic_id=topic_id
            ) + ">" + topic['Title'] + "</a>" + "&nbsp;&nbsp;中回复了你"
    return inform_title
Пример #4
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)
Пример #5
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)
Пример #6
0
def edit_topic(topic_id):
    # auth check
    topic = Topic.get_topic(topic_id)
    if topic['UserID'] != session['user_id']:
        abort(404)

    node_types = Node.get_types()
    for nt in node_types:
        nt['nodes'] = Node.get_nodes_by_type(nt['TypeID'])

    if request.method == 'GET':
        form = TopicForm(node_id=topic['NodeID'], title=topic['Title'], content=topic['Content'])
        return render_template('topic/edit_topic.html', topic=topic, node_types=node_types, form=form)
    else:
        form = TopicForm(request.form)
        if form.validate():
            # node_id = int(form.node_id.data)
            node_id = 10001
            title = cgi.escape(form.title.data)
            content = cgi.escape(form.content.data)
            new_topic_id = Topic.edit(topic_id, node_id, title, content)
            return redirect(url_for('single_topic', topic_id=topic_id))
        else:
            return render_template('topic/edit_topic.html', topic=topic, node_types=node_types, form=form)
Пример #7
0
def build_topic_inform_title(replyer_id, topic_id):
	replyer = User.get_user_by_id(replyer_id)
	topic = Topic.get_topic(topic_id)
	inform_title = "<a href=" + url_for('people', user_abbr=replyer['Abbr']) + ">" + replyer['Name'] + "</a>&nbsp;&nbsp;在话题&nbsp;&nbsp;" + "<a href=" + url_for('single_topic', topic_id=topic_id) + ">" + topic['Title'] + "</a>" + "&nbsp;&nbsp;中回复了你"
	return inform_title