--- a/candolint/handlers.py Tue Aug 23 21:37:18 2016 +0800
+++ b/candolint/handlers.py Tue Aug 23 22:17:00 2016 +0800
from __future__ import absolute_import, division
from peewee import DoesNotExist
from tornado.escape import json_decode
+class Paginator(object):
+ def __init__(self, query, page, paginate_by=30):
+ self.paginate_by = paginate_by
+ self.pages = int(ceil(query.count() / paginate_by))
+ return self.query.paginate(self.page, self.paginate_by).iterator()
class BaseHandler(RequestHandler):
if not database.is_closed():
+ def paginate(self, query):
+ page = self.get_query_argument('page', '1')
+ if page and page.isdigit():
+ page = max(1, int(page))
+ return Paginator(query, page)
def write_error(self, status_code, **kwargs):
.select(Change, *Check.get_light_fields())
- .where(Check.project == project)
+ .where(Check.project == project))
self.render('project.html', project=project, checks=checks)
--- a/candolint/uimodules.py Tue Aug 23 21:37:18 2016 +0800
+++ b/candolint/uimodules.py Tue Aug 23 22:17:00 2016 +0800
return self.render_string('ui/badges.html', check=check)
+class Pagination(UIModule):
+ def render(self, page, pages):
+ return self.render_string('ui/pagination.html', page=page, pages=pages)
--- a/templates/project.html Tue Aug 23 21:37:18 2016 +0800
+++ b/templates/project.html Tue Aug 23 22:17:00 2016 +0800
<table class="uk-table uk-table-middle uk-text-nowrap">
- {% for check in checks %}
+ {% set paged_checks = handler.paginate(checks) %}
+ {% for check in paged_checks.iterator() %}
{% set change = check.change %}
{% set adapter = project.get_adapter() %}
+ {% if paged_checks.pages > 1 %}
+ {% module Pagination(paged_checks.page, paged_checks.pages) %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/ui/pagination.html Tue Aug 23 22:17:00 2016 +0800
+<ul class="uk-pagination">
+ {% for i in range(1, pages + 1) %}
+ <li{% if page == i %} class="uk-active"{% end %}>
+ <a href="?page={{ i }}">{{ i }}</a>