WebHelpers / webhelpers / pagination / links.py

"""Pagination Link Generators"""
from webhelpers.htmlgen import html

def pagelist(page):
    """PHPbb style Pagination Links
    This returns HTML source to be included into a page. The html is generated
    with htmlgen
    paginator = page.paginator

    first_page = paginator.first
    first_window = first_page.window(padding=3)

    page_window = page.window(padding=1)

    last_page = paginator.last
    last_window = last_page.window(padding=3)

    first_past_page = first_window.last >= page_window.first
    page_past_last = page_window.last >= last_window.first

    def combine_pages(page_list):
        seen = {}
        result = []
        for page in page_list:
            if page in seen: continue
            seen[page] = 1
        return result

    if first_past_page:
        if page_past_last:
            display = first_window.pages
            first_window.last = page_window.last
            display = (first_window.pages + [None] + last_window.pages)
        if page_past_last:
            page_window.last = last_window.last
            display = (first_window.pages + [None] + page_window.pages)
            display = (first_window.pages + [None] + page_window.pages + [None]
                    + last_window.pages)

    print display

    pager_c = []
    for i in display:
        if i is None:
        elif i == page:
            pager_c.append(html.a(href=i, c=[i]))

    pager = html.div(class_='pager', c=pager_c)

    return pager
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.