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)
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 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 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 add_author(): if request.method == 'GET': dynasties = Dynasty.get_dynasties() return render_template('add_author.html', dynasties=dynasties) 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']) newAuthorID = Author.add_author(author, quote, introduction, birthYear, deathYear, dynastyID) return redirect(url_for('single_author', authorID=newAuthorID))
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 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 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 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 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 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 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 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 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 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 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 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 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)
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)