Changeset - 7433775cc53b
[Not reviewed]
default
0 2 0
Mads Kiilerich - 6 years ago 2019-11-07 03:12:41
mads@kiilerich.com
Grafted from: c8cfc73caa91
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.
2 files changed with 15 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/page.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""
 
Custom paging classes
 
"""
 
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
 

	
 

	
 
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
 
        if (cur_page <= edge):
 
            radius = max(items / 2, items - cur_page)
 
        elif (max_page - cur_page) < edge:
 
            radius = (items - 1) - (max_page - cur_page)
 
        else:
 
            radius = items / 2
 

	
 
        left = max(1, (cur_page - (radius)))
 
        right = min(max_page, cur_page + (radius))
 
        return left, cur_page, right
 

	
 
    def _range(self, regexp_match):
 
        """
 
        Return range of linked pages (e.g. '1 2 [3] 4 5 6 7 8').
 

	
 
        Arguments:
 

	
 
        regexp_match
 
            A "re" (regular expressions) match object containing the
 
            radius of linked pages around the current page in
 
            regexp_match.group(1) as a string
setup.py
Show inline comments
 
@@ -48,48 +48,50 @@ requirements = [
 
    "TurboGears2 >= 2.3.10, < 2.5",
 
    "tgext.routes >= 0.2.0, < 1",
 
    "Beaker >= 1.7.0, < 2",
 
    "WebHelpers >= 1.3, < 1.4",
 
    "WebHelpers2 >= 2.0, < 2.1",
 
    "FormEncode >= 1.3.0, < 1.4",
 
    "SQLAlchemy >= 1.1, < 1.4",
 
    "Mako >= 0.9.0, < 1.1",
 
    "Pygments >= 2.2.0, < 2.5",
 
    "Whoosh >= 2.5.0, < 2.8",
 
    "celery >= 3.1, < 4.0", # TODO: celery 4 doesn't work
 
    "Babel >= 1.3, < 2.8",
 
    "python-dateutil >= 1.5.0, < 2.9",
 
    "Markdown >= 2.2.1, < 3.2",
 
    "docutils >= 0.11, < 0.15",
 
    "URLObject >= 2.3.4, < 2.5",
 
    "Routes >= 1.13, < 2", # TODO: bumping to 2.0 will make test_file_annotation fail
 
    "dulwich >= 0.14.1, < 0.20",
 
    "mercurial >= 4.5, < 5.3",
 
    "decorator >= 3.3.2, < 4.5",
 
    "Paste >= 2.0.3, < 3.1",
 
    "bleach >= 3.0, < 3.2",
 
    "Click >= 7.0, < 8",
 
    "ipaddr >= 2.1.10, < 2.3",
 
    "paginate >= 0.5, < 0.6",
 
    "paginate_sqlalchemy >= 0.3.0, < 0.4",
 
]
 

	
 
if not is_windows:
 
    requirements.append("bcrypt >= 3.1.0, < 3.2")
 

	
 
dependency_links = [
 
]
 

	
 
classifiers = [
 
    'Development Status :: 4 - Beta',
 
    'Environment :: Web Environment',
 
    'Framework :: Pylons',
 
    'Intended Audience :: Developers',
 
    'License :: OSI Approved :: GNU General Public License (GPL)',
 
    'Operating System :: OS Independent',
 
    'Programming Language :: Python',
 
    'Programming Language :: Python :: 2.7',
 
    'Topic :: Software Development :: Version Control',
 
]
 

	
 

	
 
# additional files from project that goes somewhere in the filesystem
 
# relative to sys.prefix
 
data_files = []
0 comments (0 inline, 0 general)