Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
def collect_work(work_id):
	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))

	# collect work
	Collect.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))
Ejemplo n.º 6
0
def collect_work(work_id):
    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))

    # collect work
    Collect.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))