Files
@ 0be48652ca48
Branch filter:
Location: kallithea/kallithea/lib/page.py - annotation
0be48652ca48
2.4 KiB
text/x-python
routing: separate url handling from routing - move it to webutils
This is a helper method relying on the thread local tg.request. We didn't have
a good place to put it. Now we do.
This (re)moves unfortunate dependencies to the routing module (which almost is
a controller).
This is a helper method relying on the thread local tg.request. We didn't have
a good place to put it. Now we do.
This (re)moves unfortunate dependencies to the routing module (which almost is
a controller).
e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d e33b17db388d f49e1b6cff90 0a277465fddf 7433775cc53b 7433775cc53b 7433775cc53b feb90eac2e79 0a277465fddf 0be48652ca48 0a277465fddf e33b17db388d f49e1b6cff90 f49e1b6cff90 7691290837d2 7433775cc53b 7433775cc53b 2323e2bb2797 2323e2bb2797 2323e2bb2797 7433775cc53b 7433775cc53b 7433775cc53b 7433775cc53b 7433775cc53b feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 e33b17db388d feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 e33b17db388d feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 feb90eac2e79 | # -*- 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 paginate
import paginate_sqlalchemy
import sqlalchemy.orm
from webhelpers2.html import literal
from kallithea.lib.webutils import url
log = logging.getLogger(__name__)
class Page(paginate.Page):
def __init__(self, collection,
page=1, items_per_page=20, item_count=None,
**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 pager(self):
return literal(
paginate.Page.pager(self,
format='<ul class="pagination">$link_previous\n~4~$link_next</ul>',
link_attr={'class': 'pager_link'},
dotdot_attr={'class': 'pager_dotdot'},
separator='\n',
))
@staticmethod
def default_link_tag(item):
# based on the base class implementation, but wrapping results in <li>, and with different handling of current_page
text = item['value']
if item['type'] == 'current_page': # we need active on the li and can thus not use curpage_attr
return '''<li class="active"><span>%s</span></li>''' % text
if not item['href'] or item['type'] == 'span':
if item['attrs']:
text = paginate.make_html_tag('span', **item['attrs']) + text + '</span>'
else:
target_url = item['href']
text = paginate.make_html_tag('a', text=text, href=target_url, **item['attrs'])
return '''<li>%s</li>''' % text
|