def get_page_context(self):
"""
Return current page context
"""
paginate = self.get_argument('paginate', None)
try:
page = int(self.get_argument('page', 1))
except ValueError:
page = 1
try:
count = Record\
.select()\
.where(Record.active == True)\
.count()
except peewee.IntegrityError:
count = 0
per_page = env.RECORDS_PER_PAGE
page_count = int(count/per_page) + int(bool(count % per_page))
prev_page, page, next_page = self.paging(page, page_count)
try:
if paginate is None:
records = Record\
.select()\
.where(Record.active == True)\
.order_by(Record.name.asc())\
.paginate(
page,
paginate_by=per_page)
else:
records = Record\
.select(
Record,
RecordPage)\
.where(
RecordPage.page == page)\
.join(
RecordPage,
join_type=peewee.JOIN.INNER)\
.order_by(Record.name.asc())
except peewee.IntegrityError:
records = []
return dict(records=records,
paginate=paginate,
page_count=page_count,
prev_page=prev_page,
page=page,
next_page=next_page)
评论列表
文章目录