Mercurial > kallithea
changeset 7978:7433775cc53b
page: minimal change to move from webhelpers.paginate to paginate
webhelpers is dead and doesn't work with py3. paginate is not very actively
maintained, but it is the natural successor to webhelpers.paginate, it seems
stable, and it works with py3.
This is a minimal change that seems to work. It preserves existing tech debt
... and adds a little bit more. It will be cleaned up next.
webhelpers.paginate had built-in SqlAlchemy support - now we have to handle it
explicitly.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 07 Nov 2019 03:12:41 +0100 |
parents | 2323e2bb2797 |
children | feb90eac2e79 |
files | kallithea/lib/page.py setup.py |
diffstat | 2 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/page.py Fri Nov 08 00:23:10 2019 +0100 +++ b/kallithea/lib/page.py Thu Nov 07 03:12:41 2019 +0100 @@ -17,8 +17,10 @@ import logging import re +import paginate +import paginate_sqlalchemy +import sqlalchemy.orm from webhelpers2.html import HTML, literal -from webhelpers.paginate import Page as _Page from kallithea.config.routing import url @@ -26,15 +28,19 @@ log = logging.getLogger(__name__) -class Page(_Page): - """ - Custom pager emitting Bootstrap paginators - """ +class Page(paginate.Page): + def __init__(self, collection, page=1, items_per_page=20, item_count=None, **kwargs): - _Page.__init__(self, collection, page=page, items_per_page=items_per_page, item_count=item_count, - url=url.current, **kwargs) + if isinstance(collection, sqlalchemy.orm.query.Query): + collection = paginate_sqlalchemy.SqlalchemyOrmWrapper(collection) + paginate.Page.__init__(self, collection, page=page, items_per_page=items_per_page, item_count=item_count, + url_maker=lambda page: url.current(page=page, **kwargs)) + + def _pagerlink(self, page, text): + """hack to mimic old webhelpers.paginate internals""" + return literal('''<li><a class="pager_link" href="%s">%s</a></li>''') % (self.url_maker(page), text) def _get_pos(self, cur_page, max_page, items): edge = (items / 2) + 1