def add_author(): if request.method == 'GET': dynasties = Dynasty.get_dynasties() return render_template('author/add_author.html', dynasties=dynasties) else: author = request.form['author'] abbr = request.form['abbr'] introduction = request.form['introduction'] birthYear = request.form['birthYear'] deathYear = request.form['deathYear'] dynastyID = int(request.form['dynastyID']) Author.add_author(author, abbr, introduction, birthYear, deathYear, dynastyID) return redirect(url_for('author/single_author', author_abbr=abbr))
def edit_author(authorID): if request.method == 'GET': dynasties = Dynasty.get_dynasties() author = Author.get_author(authorID) return render_template('edit_author.html', dynasties=dynasties, author=author) elif request.method == 'POST': author = request.form['author'] quote = request.form['quote'] introduction = request.form['introduction'] birthYear = int(request.form['birthYear']) deathYear = int(request.form['deathYear']) dynastyID = int(request.form['dynastyID']) Author.edit_author(author, quote, introduction, birthYear, deathYear, dynastyID, authorID) return redirect(url_for('single_author', authorID=authorID))
def single_dynasty(dynasty_abbr): dynasty = Dynasty.get_dynasty_by_abbr(dynasty_abbr) if not dynasty: abort(404) authors_num = Author.get_authors_num_by_dynasty(dynasty['DynastyID']) authors = Author.get_authors_by_dynasty(dynasty['DynastyID'], 5, True) 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() return render_template('dynasty/single_dynasty.html', dynasty=dynasty, authors=authors, authors_num=authors_num, dynasties=dynasties)
def authors(): dynasties = Dynasty.get_dynasties() for d in dynasties: d['authors'] = Author.get_authors_by_dynasty(d['DynastyID']) for a in d['authors']: quote = Quote.get_quote_by_random(a['AuthorID']) a['Quote'] = quote['Quote'] if quote else "" a['QuotesNum'] = Quote.get_quotes_num_by_author(a['AuthorID']) hot_authors = Author.get_hot_authors(8) for a in hot_authors: quote = Quote.get_quote_by_random(a['AuthorID']) a['Quote'] = quote['Quote'] if quote else "" return render_template('authors.html', dynasties=dynasties, hot_authors=hot_authors)
def get_dynasty_by_json(): check_admin() dynasty_id = int(request.form['dynasty_id']) dynasty = Dynasty.get_dynasty(dynasty_id) authors = Author.get_authors_by_dynasty(dynasty_id) return render_template('single_dynasty.widget', dynasty=dynasty, authors=authors)
def get_authors_by_name(): name = request.form['author'] authors = Author.get_authors_by_name(name) for author in authors: author['Collections'] = Collection.get_collections_by_author( author['AuthorID']) return json.dumps(authors)
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)
def get_dynasty_by_json(): dynasty_id = int(request.form['dynasty_id']) dynasty = Dynasty.get_dynasty(dynasty_id) authors = Author.get_authors_by_dynasty(dynasty_id) return render_template('single_dynasty.widget', dynasty=dynasty, authors=authors)
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)
def edit_author(authorID): check_admin() if request.method == 'GET': dynasties = Dynasty.get_dynasties() author = Author.get_author_by_id(authorID) return render_template('edit_author.html', dynasties=dynasties, author=author) elif request.method == 'POST': author = request.form['author'] abbr = request.form['abbr'] introduction = request.form['introduction'] birthYear = request.form['birthYear'] deathYear = request.form['deathYear'] dynastyID = int(request.form['dynastyID']) Author.edit_author(author, abbr, introduction, birthYear, deathYear, dynastyID, authorID) return redirect(url_for('single_author', author_abbr=abbr))
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)
def get_authors_by_name(): check_admin() name = request.form['author'] authors = Author.get_authors_by_name(name) for author in authors: author['Collections'] = Collection.get_collections_by_author(author['AuthorID']) return json.dumps(authors)
def single_dynasty(dynasty_id): # gene html code dynasty = Dynasty.get_dynasty(dynasty_id) authors = Author.get_authors_by_dynasty(dynasty_id) dynasty_html = render_template('single_dynasty.widget', dynasty=dynasty, authors=authors) # render view dynasties = Dynasty.get_dynasties() return render_template('dynasty.html', dynasty_html=dynasty_html, dynasty_id=dynasty_id, dynasties=dynasties)
def single_dynasty(dynasty_abbr): dynasty = Dynasty.get_dynasty_by_abbr(dynasty_abbr) if not dynasty: abort(404) #dynasty['History'] = markdown2.markdown(dynasty['History']) authors = Author.get_authors_by_dynasty(dynasty['DynastyID'], 5) for a in authors: quote = Quote.get_quote_by_random(a['AuthorID']) a['Quote'] = quote['Quote'] if quote else "" authors_num = Author.get_authors_num_by_dynasty(dynasty['DynastyID']) dynasties = Dynasty.get_dynasties() return render_template('single_dynasty.html', dynasty=dynasty, authors=authors, authors_num=authors_num, dynasties=dynasties)
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)
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)
def add_author(): if request.method == 'GET': dynasties = Dynasty.query.order_by(Dynasty.start_year) return render_template('author/add_author.html', dynasties=dynasties) else: author = Author(name=request.form['name'], abbr=request.form['abbr'], intro=request.form['intro'], birth_year=request.form['birth_year'], death_year=request.form['death_year'], dynasty_id=int(request.form['dynasty_id'])) db.session.add(author) db.session.commit() return redirect(url_for('author', author_abbr=author.abbr))
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)
def admin_quotes(author_id): check_admin() author = Author.get_author_by_id(author_id) quotes = Quote.get_quotes_by_author(author_id) return render_template('admin_quotes.html', quotes=quotes, author=author)
def get_authors_by_name(): name = request.form['author'] authors = Author.get_authors_by_name(name) return json.dumps(authors)
def search_author_in_collection(): name = request.form['author'] authors = Author.get_authors_by_name(name) return json.dumps(authors)
def author(): dynasties = Dynasty.get_dynasties() for dyn in dynasties: dyn['authors'] = Author.get_authors_by_dynasty(dyn['DynastyID']) return render_template('author.html', dynasties=dynasties)