Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
0
def user_reviews(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
	user_name = '我' if is_me else user['Name']

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

	reviews = Review.get_reviews_by_user(user['UserID'], page, num_per_page, is_me)
	for r in reviews:
		r['Time'] = time_diff(r['Time'])
		
	reviews_num = Review.get_reviews_num_by_user(user['UserID'], is_me)

	# page paras
	total_page = int(math.ceil(reviews_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('user/user_reviews.html', user=user, reviews=reviews, reviews_num=reviews_num, user_name=user_name, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page)
Esempio n. 4
0
def single_work(work_id):
	work = Work.get_work(work_id)
	if not work:
		abort(404)

	# add comment, split ci, gene paragraph
	work['Content'] = re.sub(r'<([^<^b]+)>', r"<sup title='\1'></sup>", work['Content'])
	work['Content'] = work['Content'].replace('%', "&nbsp;&nbsp;")
	work['Content'] = markdown2.markdown(work['Content'])

	# check if is collected
	if 'user_id' in session:
		is_collected = Collect.check(session['user_id'], work_id)
		tags = Collect.get_tags(session['user_id'], work_id) if is_collected else ""
		my_tags = Tag.get_user_tags(session['user_id'], 20)
		popular_tags = Tag.get_work_tags(work_id, 20)
	else:
		is_collected = False
		tags = ""
		my_tags = []
		popular_tags = []

	reviews = Review.get_reviews_by_work(work_id)
	for r in reviews:
		r['Time'] = time_diff(r['Time'])

	product = Product.get_product_by_random()

	other_works = Work.get_other_works_by_author(work['AuthorID'], work_id, 5)
	for ow in other_works:
		ow['Content'] = content_clean(ow['Content'])

	collectors = Collect.get_users_by_work(work_id, 4)

	return render_template('work/single_work.html', work=work, tags=tags, my_tags=my_tags, popular_tags=popular_tags, reviews=reviews, is_collected=is_collected, product=product, other_works=other_works, collectors=collectors)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
0
def reviews():
    # pagination
    num_per_page = 10
    page = int(request.args['page'] if 'page' in request.args else 1)

    reviews = Review.get_reviews(page, num_per_page)
    for r in reviews:
        r['Time'] = time_diff(r['Time'])

    # page paras
    reviews_num = Review.get_reviews_num()
    total_page = int(math.ceil(reviews_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

    reviewers = Review.get_hot_reviewers(8)
    return render_template('reviews.html',
                           reviews=reviews,
                           reviewers=reviewers,
                           page=page,
                           total_page=total_page,
                           pre_page=pre_page,
                           next_page=next_page)
Esempio n. 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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
0
def single_work(work_id):
    work = Work.get_work(work_id)

    if not work:
        abort(404)

    # add comment, split ci, gene paragraph
    work['Content'] = re.sub(r'<([^<^b]+)>', r"<sup title='\1'></sup>",
                             work['Content'])
    work['Content'] = work['Content'].replace('%', "&nbsp;&nbsp;")
    work['Content'] = markdown2.markdown(work['Content'])

    # check is loved
    if 'user_id' in session:
        is_loved = Love_work.check_love(session['user_id'], work_id)
        tags = Love_work.get_tags(session['user_id'],
                                  work_id) if is_loved else ""
        my_tags = Tag.get_user_tags(session['user_id'], 20)
        popular_tags = Tag.get_work_tags(work_id, 20)
    else:
        is_loved = False
        tags = ""
        my_tags = []
        popular_tags = []

    reviews = Review.get_reviews_by_work(work_id)
    for r in reviews:
        r['Time'] = time_diff(r['Time'])

    widgets = Widget.get_widgets('work', work_id)

    product = Product.get_product_by_random()

    other_works = Work.get_other_works_by_author(work['AuthorID'], work_id, 5)
    for ow in other_works:
        ow['Content'] = content_clean(ow['Content'])

    lovers = Love_work.get_users_by_work(work_id, 4)

    return render_template('single_work.html',
                           work=work,
                           tags=tags,
                           my_tags=my_tags,
                           popular_tags=popular_tags,
                           reviews=reviews,
                           widgets=widgets,
                           is_loved=is_loved,
                           product=product,
                           other_works=other_works,
                           lovers=lovers)
Esempio n. 19
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)
Esempio n. 20
0
def reviews():
    # pagination
    num_per_page = 10
    page = int(request.args['page'] if 'page' in request.args else 1)

    reviews = Review.get_reviews(page, num_per_page)
    for r in reviews:
        r['Time'] = time_diff(r['Time'])

    # page paras
    reviews_num = Review.get_reviews_num()
    total_page = int(math.ceil(reviews_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

    reviewers = Review.get_hot_reviewers(8)
    return render_template('review/reviews.html', reviews=reviews, reviewers=reviewers, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page)
Esempio n. 21
0
def user_reviews(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
    user_name = '我' if is_me else user['Name']

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

    reviews = Review.get_reviews_by_user(user['UserID'], page, num_per_page,
                                         is_me)
    for r in reviews:
        r['Time'] = time_diff(r['Time'])

    reviews_num = Review.get_reviews_num_by_user(user['UserID'], is_me)

    # page paras
    total_page = int(math.ceil(reviews_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('user/user_reviews.html',
                           user=user,
                           reviews=reviews,
                           reviews_num=reviews_num,
                           user_name=user_name,
                           page=page,
                           total_page=total_page,
                           pre_page=pre_page,
                           next_page=next_page)
Esempio n. 22
0
 def friendly_create_time(self):
     return time_diff(self.create_time)
Esempio n. 23
0
 def friendly_create_time(self):
     return time_diff(self.create_time)