Example #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)
Example #2
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)
Example #3
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)
Example #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)
Example #5
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)
Example #6
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))
Example #7
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))
Example #8
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))
Example #9
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)
Example #10
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))