@register.inclusion_tag("rapidsms/templatetags/paginator.html", takes_context=True)
def paginator(context, page, prefix=""):
    """Paginator Template Tag

    Take a page from a paginator, creates links to relevant pages, and returns
    an HTML version of those links.  It links to the first
    ``rapidsms.settings.PAGINATOR_BORDER_LINKS``, last
    ``rapidsms.settings.PAGINATOR_BORDER_LINKS`` pages,
    and the ``rapidsms.settings.PAGINATOR_ADJACENT_LINKS`` pages around the
    current page.

    :param context: Template context
    :param page: Paginator page object representing the current page
    :param prefix: Prefix for the page GET parameter
    """

    dom_id = prefix + "paginator"
    page_param = prefix + "page"
    request = context["request"]

    def _link(page_number):
        return _self_link(request, **{page_param: page_number})

    def _page(number):
        return {
            "number": number,
            "link": _link(number),
            "active": (page.number == number)}

    # num_border_links represent the first N pages and last N pages in the paginator
    num_border_links = min(settings.PAGINATOR_BORDER_LINKS, page.paginator.num_pages)
    # num_adjacent_links represents the N pages around the current page
    num_adjacent_links = min(settings.PAGINATOR_ADJACENT_LINKS, page.paginator.num_pages)
    last_page_number = page.paginator.num_pages + 1

    pages = set([page.number])
    # first set of border links
    for p in range(1, num_border_links + 1):
        pages.add(p)
    # last border links
    for p in range(last_page_number - num_border_links, last_page_number):
        pages.add(p)
    # make sure that the adjacent links do not go outside of the page range
    first_adjacent = max(1, page.number - num_adjacent_links)
    last_adjacent = min(page.number + num_adjacent_links + 1, last_page_number)
    for p in range(first_adjacent, last_adjacent):
        pages.add(p)

    page_links = []
    pages = sorted(pages)
    for i in range(len(pages) - 1):
        page_links.append(_page(pages[i]))
        gap = pages[i + 1] - pages[i]
        if gap == 2:
            # if the ellipsis would only cover 1 page, add that page.
            page_links.append(_page(pages[i] + 1))
        elif gap > 2:
            # add an ellipsis when there is a gap in the pages.
            page_links.append(None)
    if pages:
        page_links.append(_page(pages[-1]))

    subcontext = {
        "dom_id": dom_id,
        "page_links": page_links}

    if page.number > 1:
        subcontext.update({
            "prev_page_link": _link(page.previous_page_number())})

    if page.number < page.paginator.num_pages:
        subcontext.update({
            "next_page_link": _link(page.next_page_number())})

    return subcontext
dataset/ETHPy150Open rapidsms/rapidsms/rapidsms/templatetags/paginator_tags.py/paginator/original