예제 #1
0
def add_topic():
    node_types = Node.get_types()
    for nt in node_types:
        nt['nodes'] = Node.get_nodes_by_type(nt['TypeID'])

    if request.method == 'GET':
        # choose a node to be default, here is node_id = 10001
        node_id = int(request.args['node_id']) if "node_id" in request.args else 10001
        form = TopicForm(node_id=node_id)
        node = Node.get_node_by_id(node_id)
        return render_template('topic/add_topic.html', node=node, 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)
            user_id = session['user_id']
            new_topic_id = Topic.add(node_id, title, content, user_id)
            return redirect(url_for('single_topic', topic_id=new_topic_id))
        else:
            # choose a node to be default, here is node_id = 10001
            # node_id = int(form.node_id.data)
            node_id = 10001
            node = Node.get_node_by_id(node_id)
            return render_template('topic/add_topic.html', node=node, node_types=node_types, form=form)
예제 #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 single_node(node_abbr):
    node = Node.get_node_by_abbr(node_abbr)
    nodes = Node.get_nodes(16)
    topics = Topic.get_topics_by_node(node_abbr)
    for t in topics:
        t['Time'] = time_diff(t['Time'])
    return render_template('topic/single_node.html', node=node, nodes=nodes, topics=topics)
예제 #4
0
def single_node(node_abbr):
    node = Node.get_node_by_abbr(node_abbr)
    if not node:
        abort(404)

    nodes = Node.get_nodes(16)
    topics = Topic.get_topics_by_node(node_abbr)
    for t in topics:
        t['Time'] = time_diff(t['Time'])
    return render_template('topic/single_node.html', node=node, nodes=nodes, topics=topics)
예제 #5
0
def topics():
    topics = Topic.get_topics(15)
    for t in topics:
        t['Time'] = time_diff(t['Time'])

    nodes = Node.get_nodes(16)

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

    return render_template('topic/topics.html', topics=topics, nodes=nodes, hot_topics=hot_topics, node_types=node_types)
예제 #6
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)
예제 #7
0
파일: topic.py 프로젝트: imgugu/xichuangzhu
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)
예제 #8
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)