class Pager(Component): """A pager component based on paginate.Page. >>> pager = Pager(None, range(100), page=4, url_maker=lambda p: 'page %s' % p) >>> assert pager.render() """ def __init__(self, req, collection, **kw): self.req = req self.page = Page(collection, **kw) def render(self): html = self.page.pager( format='<div class="pagination"><ul><li>~3~</li></ul></div>', separator='</li><li>', curpage_attr={'class': 'active'}, dotdot_attr={'class': 'disabled'}) return html\ .replace('<span ', '<a ')\ .replace('</span>', '</a>')\ .replace('<li><a class="active"', '<li class="active"><a')\ .replace('<li><a class="disabled"', '<li class="disabled"><a')
def _paginate_zones(self, zones, page, per_page, url, url_rel, pattern, index): p = Page(zones, page=page, items_per_page=per_page, item_count=zones.count()) i = url.find("/zones") + 1 link_add_delete = "" if url[i:].find('/') == -1: url_rel = 'zones/' + url_rel link_add_delete = 'zones/' pagination = p.pager(pattern, url=url_rel, dotdot_attr={'x': 5}, link_attr={'y': 6}, curpage_attr={'z': 77}) return { "zones": p, "pagination": pagination, "index": index, "link_add_delete": link_add_delete }