Exemplo n.º 1
0
def logout():
	check_login()
	
	session.pop('user_id', None)
	session.pop('user_name', None)
	session.pop('user_abbr', None)
	return redirect(url_for('index'))
Exemplo n.º 2
0
def love_work(work_id):
	check_login()

	tags = request.form['tags'].split(' ')

	# remove the empty & repeat item
	new_tags = []
	for t in tags:
		if t != '':
			new_tags.append(t)
	new_tags = list(set(new_tags))

	# add love work
	is_loved = Love_work.check_love(session['user_id'], work_id)
	if is_loved:
		Love_work.edit(session['user_id'], work_id, ' '.join(new_tags) + ' ')
	else:
		Love_work.add(session['user_id'], work_id, ' '.join(new_tags) + ' ')

	# update user tags & work tags
	for t in new_tags:
		Tag.add_tag(t)
		Tag.add_user_tag(session['user_id'], t)
		Tag.add_work_tag(work_id, t)

	return redirect(url_for('single_work', work_id=work_id))
Exemplo n.º 3
0
def informs():
	check_login()
	
	# pagination
	num_per_page = 10
	page = int(request.args['page'] if 'page' in request.args else 1)
	
	informs = Inform.get_informs(session['user_id'], page, num_per_page)
	for i in informs:
		i['Time'] = time_diff(i['Time'])

	# page paras
	informs_num = Inform.get_informs_num(session['user_id'])
	#return str(informs_num)
	total_page = int(math.ceil(informs_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

	new_informs_num = Inform.get_new_informs_num(session['user_id'])

	Inform.update_check_inform_time(session['user_id'])

	return render_template('informs.html', informs=informs, new_informs_num=new_informs_num, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page)
Exemplo n.º 4
0
def add_topic():
    check_login()

    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('add_topic.html',
                               node=node,
                               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)
            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 = Node.get_node_by_id(node_id)
            return render_template('add_topic.html',
                                   node=node,
                                   node_types=node_types,
                                   form=form)
Exemplo n.º 5
0
def add_comment_to_topic(topic_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_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))
Exemplo n.º 6
0
def love_work(work_id):
    check_login()

    tags = request.form['tags'].split(' ')

    # remove the empty & repeat item
    new_tags = []
    for t in tags:
        if t != '':
            new_tags.append(t)
    new_tags = list(set(new_tags))

    # add love work
    is_loved = Love_work.check_love(session['user_id'], work_id)
    if is_loved:
        Love_work.edit(session['user_id'], work_id, ' '.join(new_tags) + ' ')
    else:
        Love_work.add(session['user_id'], work_id, ' '.join(new_tags) + ' ')

    # update user tags & work tags
    for t in new_tags:
        Tag.add_tag(t)
        Tag.add_user_tag(session['user_id'], t)
        Tag.add_work_tag(work_id, t)

    return redirect(url_for('single_work', work_id=work_id))
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
def add_review(work_id):
    check_login()
    work = Work.get_work(work_id)

    if request.method == 'GET':
        form = ReviewForm()
        return render_template('add_review.html', work=work, form=form)
    elif request.method == 'POST':
        form = ReviewForm(request.form)
        if form.validate():
            user_id = session['user_id']
            title = cgi.escape(form.title.data)
            content = cgi.escape(form.content.data)
            new_review_id = Review.add_review(work_id, user_id, title, content)
            return redirect(url_for('single_review', review_id=new_review_id))
        else:
            return render_template('add_review.html', work=work, form=form)
Exemplo n.º 9
0
def add_review(work_id):
	check_login()
	work = Work.get_work(work_id)
	
	if request.method == 'GET':
		form = ReviewForm()
		return render_template('add_review.html', work=work, form=form)
	elif request.method == 'POST':
		form = ReviewForm(request.form)
		if form.validate():
			user_id = session['user_id']
			title = cgi.escape(form.title.data)
			content = cgi.escape(form.content.data)
			new_review_id = Review.add_review(work_id, user_id, title, content)
			return redirect(url_for('single_review', review_id=new_review_id))
		else:
			return render_template('add_review.html', work=work, form=form)
Exemplo n.º 10
0
def rm_love_work(work_id):
	check_login()

	Love_work.remove(session['user_id'], work_id)
	return redirect(url_for('single_work', work_id=work_id))
Exemplo n.º 11
0
def rm_love_work(work_id):
    check_login()

    Love_work.remove(session['user_id'], work_id)
    return redirect(url_for('single_work', work_id=work_id))