def get_poem(poet_id, dynasty=1, temp='tang-poem.html'): """ get poem through alterable param :param poet_id: poet id :param dynasty: specifies dynasty :param temp: front page template :return: poem """ page = request.args.get('page', 1, type=int) now = datetime.date.today() lundar = Lunar(datetime.datetime.now()) week = datetime.datetime.isoweekday(datetime.datetime.now()) if poet_id is None: pagination = Poet.query.filter(Poet.dynasty_id == dynasty).paginate(page=page, per_page=100) authors = pagination.items if dynasty == 1: poems = Poem.query.filter(Poem.author_id <= 3667).order_by(func.random()).limit(10) else: poems = Poem.query.filter(Poem.author_id > 3667).order_by(func.random()).limit(10) return render_template('main/tool/{}'.format(temp), date=now, week=WEEKDAY.get(week), lundar=lundar, authors=authors, pagination=pagination, poems=poems, title='随机推荐', tag=0) else: authors = Poet.query.filter(Poet.dynasty_id == dynasty).order_by(func.random()).limit(100) author = Poet.query.get_or_404(poet_id) pagination2 = Poem.query.filter_by(author_id=author.id).paginate(page=page, per_page=10) poems = pagination2.items return render_template('main/tool/{}'.format(temp), date=now, week=WEEKDAY.get(week), lundar=lundar, authors=authors, poems=poems, pagination2=pagination2, tag=1, title=author.name, author=author)
def ci_song(poet_id=None): page = request.args.get('page', 1, type=int) now = datetime.date.today() lundar = Lunar(datetime.datetime.now()) week = datetime.datetime.isoweekday(datetime.datetime.now()) if poet_id is None: cis = SongCi.query.order_by(func.random()).limit(10) pagination = SongCiAuthor.query.paginate(page=page, per_page=100) authors = pagination.items return render_template('main/tool/song-ci.html', lundar=lundar, date=now, week=WEEKDAY.get(week), title='随机推荐', cis=cis, authors=authors, pagination=pagination, tag=0) else: poet = SongCiAuthor.query.get_or_404(poet_id) pagination = SongCi.query.filter_by(author_id=poet.id).paginate( page=page, per_page=10) cis = pagination.items authors = SongCiAuthor.query.order_by(func.random()).limit(100) return render_template('main/tool/song-ci.html', lundar=lundar, date=now, week=WEEKDAY.get(week), title=poet.name, cis=cis, authors=authors, author=poet, pagination2=pagination, tag=1)
def ts_poem(): poem = Poem.query.order_by(func.random()).limit(1)[0] now = datetime.date.today() lundar = Lunar(datetime.datetime.now()) return render_template('main/poem/ts-poem.html', poem=poem, now=now, lundar=lundar)
def song_ci(): ci = SongCi.query.order_by(func.random()).limit(1)[0] now = datetime.date.today() lundar = Lunar(datetime.datetime.now()) return render_template('main/poem/song-ci.html', ci=ci, now=now, lundar=lundar)