Beispiel #1
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)
Beispiel #2
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)