Beispiel #1
0
def works():
	num_per_page = 10

	work_type = request.args['type'] if 'type' in request.args else 'all'
	dynasty_abbr = request.args['dynasty'] if 'dynasty' in request.args else 'all'
	page = int(request.args['page'] if 'page' in request.args else 1)

	works = Work.get_works(work_type, dynasty_abbr, page, num_per_page)
	for work in works:
		work['Content'] = content_clean(work['Content'])

	works_num = Work.get_works_num(work_type, dynasty_abbr)

	# page paras
	total_page = int(math.ceil(works_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

	work_types = Work.get_types()

	dynasties = Dynasty.get_dynasties()

	return render_template('work/works.html', works=works, works_num=works_num, work_types=work_types, dynasties=dynasties, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page, work_type=work_type, dynasty_abbr=dynasty_abbr)
Beispiel #2
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)
Beispiel #3
0
def single_author(author_abbr):
    author = Author.get_author_by_abbr(author_abbr)
    if not author:
        abort(404)

    # if 'q' in form.args, then display it,
    # otherwise, display a random quote
    if 'q' in request.args:
        q_id = int(request.args['q'])
        quote = Quote.get_quote_by_id(q_id)
    else:
        quote = Quote.get_quote_by_random(author['AuthorID'])

    quotes_num = Quote.get_quotes_num_by_author(author['AuthorID'])

    works = Work.get_works_by_author(author['AuthorID'])
    for work in works:
        work['Content'] = content_clean(work['Content'])

    # count num of different type work.
    # return like this - works_num['shi'] = {'type_name': '诗', 'num': 0}.
    work_types = Work.get_types()
    works_num = {}
    for wt in work_types:
        works_num[wt['WorkType']] = {'type_name': wt['TypeName'], 'num': 0}
    for work in works:
        work_type = work['Type']
        works_num[work_type]['num'] += 1

    return render_template('author/single_author.html',
                           author=author,
                           quote=quote,
                           quotes_num=quotes_num,
                           works=works,
                           works_num=works_num)
Beispiel #4
0
def single_author(author_abbr):
	author = Author.get_author_by_abbr(author_abbr)

	if not author:
		abort(404)
	
	quote = Quote.get_quote_by_random(author['AuthorID'])
	quotes_num = Quote.get_quotes_num_by_author(author['AuthorID'])

	collections = Collection.get_collections_by_author(author['AuthorID'])

	works = Work.get_works_by_author(author['AuthorID'])
	for work in works:
		work['Content'] = content_clean(work['Content'])

	# count num of different type work.
	# return like this - works_num['shi'] = {'type_name': '诗', 'num': 0}.
	work_types = Work.get_types()
	works_num = {}
	for wt in work_types:
		works_num[wt['WorkType']] = {'type_name': wt['TypeName'], 'num': 0}
	for work in works:
		work_type = work['Type']  
		works_num[work_type]['num'] += 1

	return render_template('single_author.html', author=author, quote=quote, quotes_num=quotes_num, collections=collections, works=works, works_num=works_num)
Beispiel #5
0
def works_by_tag(tag):
    num_per_page = 10

    page = int(request.args['page'] if 'page' in request.args else 1)

    works = Work.get_works_by_tag(tag, page, num_per_page)
    for work in works:
        work['Content'] = content_clean(work['Content'])

    works_num = Work.get_works_num_by_tag(tag)

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

    return render_template('work/works_by_tag.html',
                           works=works,
                           tag=tag,
                           page=page,
                           total_page=total_page,
                           pre_page=pre_page,
                           next_page=next_page)
Beispiel #6
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 #7
0
def single_author(author_abbr):
    author = Author.get_author_by_abbr(author_abbr)

    if not author:
        abort(404)

    quote = Quote.get_quote_by_random(author['AuthorID'])
    quotes_num = Quote.get_quotes_num_by_author(author['AuthorID'])

    collections = Collection.get_collections_by_author(author['AuthorID'])

    works = Work.get_works_by_author(author['AuthorID'])
    for work in works:
        work['Content'] = content_clean(work['Content'])

    # count num of different type work.
    # return like this - works_num['shi'] = {'type_name': '诗', 'num': 0}.
    work_types = Work.get_types()
    works_num = {}
    for wt in work_types:
        works_num[wt['WorkType']] = {'type_name': wt['TypeName'], 'num': 0}
    for work in works:
        work_type = work['Type']
        works_num[work_type]['num'] += 1

    return render_template('single_author.html',
                           author=author,
                           quote=quote,
                           quotes_num=quotes_num,
                           collections=collections,
                           works=works,
                           works_num=works_num)
Beispiel #8
0
def single_author(author_abbr):
	author = Author.get_author_by_abbr(author_abbr)
	if not author:
		abort(404)
	
	# if 'q' in form.args, then display it,
	# otherwise, display a random quote
	if 'q' in request.args:
		q_id = int(request.args['q'])
		quote = Quote.get_quote_by_id(q_id)
	else:
		quote = Quote.get_quote_by_random(author['AuthorID'])
	
	quotes_num = Quote.get_quotes_num_by_author(author['AuthorID'])

	works = Work.get_works_by_author(author['AuthorID'])
	for work in works:
		work['Content'] = content_clean(work['Content'])

	# count num of different type work.
	# return like this - works_num['shi'] = {'type_name': '诗', 'num': 0}.
	work_types = Work.get_types()
	works_num = {}
	for wt in work_types:
		works_num[wt['WorkType']] = {'type_name': wt['TypeName'], 'num': 0}
	for work in works:
		work_type = work['Type']  
		works_num[work_type]['num'] += 1

	return render_template('author/single_author.html', author=author, quote=quote, quotes_num=quotes_num, works=works, works_num=works_num)
Beispiel #9
0
def single_author(authorID):
	author = Author.get_author(authorID)
	collections = Collection.get_collections_by_author(authorID)
	works = Work.get_works_by_author(authorID)
	for work in works:
		work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
		work['Content'] = work['Content'].replace('%', '').replace('/', '')
	worksNum = Work.get_works_num(works)
	return render_template('single_author.html', author=author, collections=collections, works=works, worksNum=worksNum)
Beispiel #10
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)
Beispiel #11
0
def add_work_image(work_id):
    if request.method == 'GET':
        work = Work.get_work(work_id)
        return render_template('work/add_work_image.html', work=work)
    else:
        # Add mtype
        desc = request.form['desc']
        image = request.files['image']

        # Save image
        image_filename = str(uuid.uuid1()) + '.' + image.filename.split('.')[-1]
        image.save(config.IMAGE_PATH + image_filename)

        image_id = Work.add_image(work_id, session['user_id'], config.IMAGE_URL + image_filename, desc)
        return redirect(url_for('work_image', work_id=work_id, image_id=image_id))
Beispiel #12
0
def edit_work(work_id):
	if request.method == 'GET':
		work = Work.get_work(work_id)
		return render_template('edit_work.html', work=work)
	elif request.method == 'POST':
		title        = request.form['title']
		content      = request.form['content']
		foreword     = request.form['foreword']
		intro        = request.form['introduction']
		authorID     = int(request.form['authorID'])
		dynastyID    = Dynasty.get_dynastyID_by_author(authorID)
		collectionID = int(request.form['collectionID'])
		type         = request.form['type']
		Work.edit_work(title, content, foreword, intro ,authorID, dynastyID, collectionID, type, work_id)
		return redirect(url_for('single_work', work_id=work_id))
Beispiel #13
0
def single_collection(collectionID):
	collection = Collection.get_collection(collectionID)
	works      = Work.get_works_by_collection(collectionID)
	for work in works:
		work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
		work['Content'] = work['Content'].replace('%', '').replace('/', '')
	return render_template('single_collection.html', collection=collection, works=works)
Beispiel #14
0
def edit_work(work_id):
    if request.method == 'GET':
        work = Work.get_work(work_id)
        return render_template('edit_work.html', work=work)
    elif request.method == 'POST':
        title = request.form['title']
        content = request.form['content']
        foreword = request.form['foreword']
        intro = request.form['introduction']
        authorID = int(request.form['authorID'])
        dynastyID = Dynasty.get_dynastyID_by_author(authorID)
        collectionID = int(request.form['collectionID'])
        type = request.form['type']
        Work.edit_work(title, content, foreword, intro, authorID, dynastyID,
                       collectionID, type, work_id)
        return redirect(url_for('single_work', work_id=work_id))
Beispiel #15
0
def single_work(work_id):
	work = Work.get_work(work_id)
	# add comment
	work['Content'] = re.sub(r'<([^<^b]+)>', r"<sup title='\1'></sup>", work['Content'])
	work['Content'] = work['Content'].replace('%', "&nbsp;&nbsp;")

	# count the geci's padding left
	if work['Type'] == "geci":
		paras = work['Content'].split('/')[0].split('\r\n\r\n')
		total_word_len = 0
		total_row_num = 0
		for para in paras:
			if len(para) != 0:
				total_word_len += len(para)
				total_row_num += 1
		geci_padding_left = (36 - total_word_len / total_row_num) / 2 + 1
	else:
		geci_padding_left = '0'

	# gene paragraph
	work['Content'] = markdown2.markdown(work['Content'])

	# add bank row
	work['Content'] = work['Content'].replace('<p>/</p>', "<div class='bank'></div>")

	reviews = Review.get_reviews_by_work(work_id)
	
	widgets = Widget.get_widgets('work', work_id)

	# check is loved
	if 'user_id' in session:
		is_loved = Love.check_love(session['user_id'], work_id)
	else:
		is_loved = False
	return render_template('single_work.html', work=work, reviews=reviews, widgets=widgets, is_loved=is_loved, geci_padding_left=geci_padding_left)
Beispiel #16
0
def add_work():
	if request.method == 'GET':
		work_types = Work.get_types()
		return render_template('work/add_work.html', work_types=work_types)
	else:
		title = request.form['title']
		content = request.form['content']
		foreword = request.form['foreword']
		intro = request.form['introduction']
		authorID = int(request.form['authorID'])
		dynastyID = int(Dynasty.get_dynastyID_by_author(authorID))
		work_type = request.form['type']
		type_name = Work.get_type_name(work_type)
		
		new_work_id = Work.add_work(title, content, foreword, intro, authorID, dynastyID, work_type, type_name)
		return redirect(url_for('single_work', work_id=new_work_id))
Beispiel #17
0
def add_quote(author_id):
    check_admin()

    quote = request.form['quote']
    work_id = int(request.form['work-id'])
    work_title = Work.get_work(work_id)['Title']
    Quote.add(author_id, quote, work_id, work_title)
    return redirect(url_for('admin_quotes', author_id=author_id))
Beispiel #18
0
def single_collection(collectionID):
    collection = Collection.get_collection(collectionID)
    works = Work.get_works_by_collection(collectionID)
    for work in works:
        work['Content'] = content_clean(work['Content'])
    return render_template('single_collection.html',
                           collection=collection,
                           works=works)
Beispiel #19
0
def add_quote(author_id):
	check_admin()

	quote = request.form['quote']
	work_id = int(request.form['work-id'])
	work_title = Work.get_work(work_id)['Title'] 
	Quote.add(author_id, quote, work_id, work_title)
	return redirect(url_for('admin_quotes', author_id=author_id))
Beispiel #20
0
def add_work():
    if request.method == 'GET':
        work_types = Work.get_types()
        return render_template('work/add_work.html', work_types=work_types)
    else:
        title = request.form['title']
        content = request.form['content']
        foreword = request.form['foreword']
        intro = request.form['introduction']
        authorID = int(request.form['authorID'])
        dynastyID = int(Dynasty.get_dynastyID_by_author(authorID))
        work_type = request.form['type']
        type_name = Work.get_type_name(work_type)

        new_work_id = Work.add_work(title, content, foreword, intro, authorID,
                                    dynastyID, work_type, type_name)
        return redirect(url_for('single_work', work_id=new_work_id))
Beispiel #21
0
def index():
	works = Work.get_works_by_random(4)
	for work in works:
		work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
		work['Content'] = work['Content'].replace('%', '')
	reviews = Review.get_reviews_by_random(5)
	authors = Author.get_authors_by_random(5)
	dynasties = Dynasty.get_dynasties()
	return render_template('index.html', works=works, reviews=reviews, authors=authors, dynasties=dynasties)
Beispiel #22
0
def add_work_image(work_id):
    if request.method == 'GET':
        work = Work.get_work(work_id)
        return render_template('work/add_work_image.html', work=work)
    else:
        # Add mtype
        desc = request.form['desc']
        image = request.files['image']

        # Save image
        image_filename = str(
            uuid.uuid1()) + '.' + image.filename.split('.')[-1]
        image.save(config.IMAGE_PATH + image_filename)

        image_id = Work.add_image(work_id, session['user_id'],
                                  config.IMAGE_URL + image_filename, desc)
        return redirect(
            url_for('work_image', work_id=work_id, image_id=image_id))
Beispiel #23
0
def add_work():
    if request.method == 'GET':
        work_types = WorkType.query
        return render_template('work/add_work.html', work_types=work_types)
    else:        
        work = Work(title=request.form['title'], content=request.form['content'], foreword=request.form['foreword'], intro=request.form['intro'], author_id = int(request.form['author_id']), type_id=request.form['type_id'])
        db.session.add(work)
        db.session.commit()
        return redirect(url_for('work', work_id=work.id))
Beispiel #24
0
def edit_quote(quote_id):	
	if request.method == 'GET':
		quote = Quote.get_quote_by_id(quote_id)
		return render_template('author/edit_quote.html', quote=quote)
	else:
		quote = request.form['quote']
		work_id = int(request.form['work-id'])
		work = Work.get_work(work_id)
		Quote.edit(quote_id, work['AuthorID'], quote, work['WorkID'], work['Title'])
		return redirect(url_for('author/admin_quotes', author_id=work['AuthorID']))
Beispiel #25
0
def add_review(work_id):
	if request.method == 'GET':
		work = Work.get_work(work_id)
		return render_template('add_review.html', work=work)
	elif request.method == 'POST':
		user_id = int(request.form['user_id'])
		title = request.form['title']
		content = request.form['content']
		new_review_id = Review.add_review(work_id, user_id, title, content)
		return redirect(url_for('single_review', review_id=new_review_id))
Beispiel #26
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)
Beispiel #27
0
def edit_work(work_id):
	check_admin()

	if request.method == 'GET':
		work = Work.get_work(work_id)
		work_types = Work.get_types()
		return render_template('edit_work.html', work=work, work_types=work_types)
	elif request.method == 'POST':
		title = request.form['title']
		content = request.form['content']
		foreword = request.form['foreword']
		intro = request.form['introduction']
		author_id = int(request.form['authorID'])
		dynasty_id = int(Dynasty.get_dynastyID_by_author(author_id))
		collection_id = int(request.form['collectionID'])
		work_type = request.form['type']
		type_name = Work.get_type_name(work_type)

		Work.edit_work(title, content, foreword, intro ,author_id, dynasty_id, collection_id, work_type, type_name, work_id)
		return redirect(url_for('single_work', work_id=work_id))
Beispiel #28
0
def edit_quote(quote_id):
    if request.method == 'GET':
        quote = Quote.get_quote_by_id(quote_id)
        return render_template('author/edit_quote.html', quote=quote)
    else:
        quote = request.form['quote']
        work_id = int(request.form['work-id'])
        work = Work.get_work(work_id)
        Quote.edit(quote_id, work['AuthorID'], quote, work['WorkID'],
                   work['Title'])
        return redirect(
            url_for('author/admin_quotes', author_id=work['AuthorID']))
Beispiel #29
0
def index():
    works = Work.get_works_by_random(4)
    for work in works:
        work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
        work['Content'] = work['Content'].replace('%', '')
    reviews = Review.get_reviews_by_random(5)
    authors = Author.get_authors_by_random(5)
    dynasties = Dynasty.get_dynasties()
    return render_template('index.html',
                           works=works,
                           reviews=reviews,
                           authors=authors,
                           dynasties=dynasties)
Beispiel #30
0
def works():
    num_per_page = 10

    work_type = request.args['type'] if 'type' in request.args else 'all'
    dynasty_abbr = request.args[
        'dynasty'] if 'dynasty' in request.args else 'all'
    page = int(request.args['page'] if 'page' in request.args else 1)

    works = Work.get_works(work_type, dynasty_abbr, page, num_per_page)
    for work in works:
        work['Content'] = content_clean(work['Content'])

    works_num = Work.get_works_num(work_type, dynasty_abbr)

    # page paras
    total_page = int(math.ceil(works_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

    work_types = Work.get_types()

    dynasties = Dynasty.get_dynasties()

    return render_template('work/works.html',
                           works=works,
                           works_num=works_num,
                           work_types=work_types,
                           dynasties=dynasties,
                           page=page,
                           total_page=total_page,
                           pre_page=pre_page,
                           next_page=next_page,
                           work_type=work_type,
                           dynasty_abbr=dynasty_abbr)
Beispiel #31
0
def edit_work(work_id):
    check_admin()

    if request.method == 'GET':
        work = Work.get_work(work_id)
        work_types = Work.get_types()
        return render_template('edit_work.html',
                               work=work,
                               work_types=work_types)
    elif request.method == 'POST':
        title = request.form['title']
        content = request.form['content']
        foreword = request.form['foreword']
        intro = request.form['introduction']
        author_id = int(request.form['authorID'])
        dynasty_id = int(Dynasty.get_dynastyID_by_author(author_id))
        collection_id = int(request.form['collectionID'])
        work_type = request.form['type']
        type_name = Work.get_type_name(work_type)

        Work.edit_work(title, content, foreword, intro, author_id, dynasty_id,
                       collection_id, work_type, type_name, work_id)
        return redirect(url_for('single_work', work_id=work_id))
Beispiel #32
0
def works_by_tag(tag):
	num_per_page = 10

	page = int(request.args['page'] if 'page' in request.args else 1)

	works = Work.get_works_by_tag(tag, page, num_per_page)
	for work in works:
		work['Content'] = content_clean(work['Content'])

	works_num = Work.get_works_num_by_tag(tag)

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

	return render_template('work/works_by_tag.html', works=works, tag=tag, page=page, total_page=total_page, pre_page=pre_page, next_page=next_page)
Beispiel #33
0
def add_review(work_id):
    work = Work.get_work(work_id)
    if request.method == 'GET':
        form = ReviewForm()
        return render_template('review/add_review.html', work=work, form=form)
    else:
        form = ReviewForm(request.form)
        if form.validate():
            user_id = session['user_id']
            title = cgi.escape(form.title.data)
            content = cgi.escape(form.content.data)
            is_publish = 1 if 'publish' in request.form else 0
            new_review_id = Review.add_review(work_id, user_id, title, content, is_publish)
            return redirect(url_for('single_review', review_id=new_review_id))
        else:
            return render_template('review/add_review.html', work=work, form=form)
Beispiel #34
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)
Beispiel #35
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)
Beispiel #36
0
def single_work(work_id):
    work = Work.get_work(work_id)
    # add comment
    work['Content'] = re.sub(r'<([^<^b]+)>', r"<sup title='\1'></sup>",
                             work['Content'])
    work['Content'] = work['Content'].replace('%', "&nbsp;&nbsp;")

    # count the geci's padding left
    if work['Type'] == "geci":
        paras = work['Content'].split('/')[0].split('\r\n\r\n')
        total_word_len = 0
        total_row_num = 0
        for para in paras:
            if len(para) != 0:
                total_word_len += len(para)
                total_row_num += 1
        geci_padding_left = (36 - total_word_len / total_row_num) / 2 + 1
    else:
        geci_padding_left = '0'

    # gene paragraph
    work['Content'] = markdown2.markdown(work['Content'])

    # add bank row
    work['Content'] = work['Content'].replace('<p>/</p>',
                                              "<div class='bank'></div>")

    reviews = Review.get_reviews_by_work(work_id)

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

    # check is loved
    if 'user_id' in session:
        is_loved = Love.check_love(session['user_id'], work_id)
    else:
        is_loved = False
    return render_template('single_work.html',
                           work=work,
                           reviews=reviews,
                           widgets=widgets,
                           is_loved=is_loved,
                           geci_padding_left=geci_padding_left)
Beispiel #37
0
def work_image(work_id, image_id):
    work = Work.get_work(work_id)
    work['Content'] = content_clean(work['Content'])
    image = Work.get_image(image_id)
    return render_template('work/work_image.html', work=work, image=image)
Beispiel #38
0
def four_works():
    works = Work.get_works_by_random(4)
    for work in works:
        work['Content'] = content_clean(work['Content'])
    return render_template('macro/index_works.widget', works=works)
Beispiel #39
0
def works():
	works = Work.get_works()
	for work in works:
		work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
		work['Content'] = work['Content'].replace('%', '').replace('/', '')
	return render_template('works.html', works=works)
Beispiel #40
0
def work_image(work_id, image_id):
    work = Work.get_work(work_id)
    work['Content'] = content_clean(work['Content'])
    image = Work.get_image(image_id)
    return render_template('work/work_image.html', work=work, image=image)
Beispiel #41
0
def works():
    works = Work.get_works()
    for work in works:
        work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
        work['Content'] = work['Content'].replace('%', '').replace('/', '')
    return render_template('works.html', works=works)
Beispiel #42
0
def single_collection(collectionID):
	collection = Collection.get_collection(collectionID)
	works = Work.get_works_by_collection(collectionID)
	for work in works:
		work['Content'] = content_clean(work['Content'])
	return render_template('single_collection.html', collection=collection, works=works)
Beispiel #43
0
def four_works():
    works = Work.get_works_by_random(4)
    for work in works:
        work['Content'] = content_clean(work['Content'])
    return render_template('four_works.widget', works=works)