Exemple #1
0
def user(user_abbr):
    user = User.get_user_by_abbr(user_abbr)
    is_me = True if "user_id" in session and session['user_id'] == user[
        'UserID'] else False

    # works
    works = Collect.get_works_by_user(user['UserID'], 1, 3)
    for work in works:
        work['Content'] = content_clean(work['Content'])
    works_num = Collect.get_works_num_by_user(user['UserID'])

    # reivews
    reviews = Review.get_reviews_by_user(user['UserID'], 1, 3, is_me)
    for r in reviews:
        r['Time'] = time_diff(r['Time'])
    reviews_num = Review.get_reviews_num_by_user(user['UserID'], is_me)

    # topics
    topics = Topic.get_topics_by_user(user['UserID'], 1, 3)
    for t in topics:
        t['Time'] = time_diff(t['Time'])
    topics_num = Topic.get_topics_num_by_user(user['UserID'])

    return render_template('user/user.html',
                           user=user,
                           works=works,
                           works_num=works_num,
                           reviews=reviews,
                           reviews_num=reviews_num,
                           topics=topics,
                           topics_num=topics_num)
Exemple #2
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))
Exemple #3
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)
Exemple #4
0
def people_topics(user_abbr):
	people = User.get_user_by_abbr(user_abbr)
	user_name = '我' if "user_id" in session and session['user_id'] == people['UserID'] else people['Name']

	# pagination
	num_per_page = 10
	page = int(request.args['page'] if 'page' in request.args else 1)

	topics = Topic.get_topics_by_user(people['UserID'], page, num_per_page)
	for t in topics:
		t['Time'] = time_diff(t['Time'])

	topics_num = Topic.get_topics_num_by_user(people['UserID'])

	# page paras
	total_page = int(math.ceil(topics_num / num_per_page))
	pre_page = (page - 1) if page > 1 else 1
	if total_page == 0:
		next_page = 1
	elif page < total_page:
		next_page = page + 1
	else:
		next_page = total_page

	return render_template('people_topics.html', people=people, topics=topics, user_name=user_name, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page)
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
0
def index():
    works = Work.get_works_by_random(4)
    for work in works:
        work['Content'] = content_clean(work['Content'])

    work_images = Work.get_images_by_random(9)

    reviews = Review.get_reviews_by_random(4)
    for r in reviews:
        r['Time'] = time_diff(r['Time'])

    authors = Author.get_authors_by_random(5)
    for a in authors:
        quote = Quote.get_quote_by_random(a['AuthorID'])
        a['Quote'] = quote['Quote'] if quote else ""
        a['QuoteID'] = quote['QuoteID'] if quote else 0

    dynasties = Dynasty.get_dynasties()
    topics = Topic.get_topics(8)
    return render_template('site/index.html',
                           works=works,
                           work_images=work_images,
                           reviews=reviews,
                           authors=authors,
                           dynasties=dynasties,
                           topics=topics)
Exemple #11
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
Exemple #12
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)
Exemple #13
0
def people(user_abbr):
	people = User.get_user_by_abbr(user_abbr)
	user_name = '我' if "user_id" in session and session['user_id'] == people['UserID'] else people['Name']

	works = Love_work.get_works_by_user(people['UserID'], 1, 3)
	for work in works:
		work['Content'] = content_clean(work['Content'])
	works_num = Love_work.get_works_num_by_user(people['UserID'])

	reviews = Review.get_reviews_by_user(people['UserID'], 1, 3)
	for r in reviews:
		r['Time'] = time_diff(r['Time'])
	reviews_num = Review.get_reviews_num_by_user(people['UserID'])

	topics = Topic.get_topics_by_user(people['UserID'], 1, 3)
	for t in topics:
		t['Time'] = time_diff(t['Time'])
	topics_num = Topic.get_topics_num_by_user(people['UserID'])

	return render_template('people.html', people=people, works=works, works_num=works_num, reviews=reviews, reviews_num=reviews_num, topics=topics, topics_num=topics_num, user_name=user_name)
Exemple #14
0
def user(user_abbr):
	user = User.get_user_by_abbr(user_abbr)
	is_me = True if "user_id" in session and session['user_id'] == user['UserID'] else False

	# works
	works = Collect.get_works_by_user(user['UserID'], 1, 3)
	for work in works:
		work['Content'] = content_clean(work['Content'])
	works_num = Collect.get_works_num_by_user(user['UserID'])

	# reivews
	reviews = Review.get_reviews_by_user(user['UserID'], 1, 3, is_me)
	for r in reviews:
		r['Time'] = time_diff(r['Time'])
	reviews_num = Review.get_reviews_num_by_user(user['UserID'], is_me)

	# topics
	topics = Topic.get_topics_by_user(user['UserID'], 1, 3)
	for t in topics:
		t['Time'] = time_diff(t['Time'])
	topics_num = Topic.get_topics_num_by_user(user['UserID'])

	return render_template('user/user.html', user=user, works=works, works_num=works_num, reviews=reviews, reviews_num=reviews_num, topics=topics, topics_num=topics_num)
Exemple #15
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)
Exemple #16
0
def add_topic():
    if request.method == 'GET':
        form = TopicForm()
        return render_template('topic/add_topic.html', form=form)
    else:
        form = TopicForm(request.form)
        if form.validate():
            topic = Topic(title=cgi.escape(form.title.data),
                          content=cgi.escape(form.content.data),
                          user_id=session['user_id'])
            db.session.add(topic)
            db.session.commit()
            return redirect(url_for('topic', topic_id=topic.id))
        else:
            return render_template('topic/add_topic.html', form=form)
Exemple #17
0
def index():
	works = Work.get_works_by_random(4)
	for work in works:
		work['Content'] = content_clean(work['Content'])

	reviews = Review.get_reviews_by_random(4)
	for r in reviews:
		r['Time'] = time_diff(r['Time'])
	
	authors = Author.get_authors_by_random(5)
	for a in authors:
		quote = Quote.get_quote_by_random(a['AuthorID'])
		a['Quote'] = quote['Quote'] if quote else ""
	
	dynasties = Dynasty.get_dynasties()
	topics = Topic.get_topics(8)
	return render_template('index.html', works=works, reviews=reviews, authors=authors, dynasties=dynasties, topics=topics)
Exemple #18
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