@contextfunction
def pager(context, items, plength=None):
    "Pager"
    request = context['request']

    response_format = 'html'
    if 'response_format' in context:
        response_format = context['response_format']

    skip = 0
    if 'page_skip' in request.GET:
        try:
            skip = long(request.GET['page_skip'])
        except Exception:
            pass

    if not plength:
        plength = getattr(settings, 'HARDTREE_PAGINATOR_LENGTH', 10)
    if hasattr(items, 'count'):
        try:
            items_length = items.count()
        except:
            items_length = len(items)
    else:
        items_length = len(items)
    pagenum = items_length // plength

    if items_length % plength:
        pagenum += 1

    maxpages = getattr(settings, 'HARDTREE_PAGINATOR_PAGES', 20)

    current = skip // plength
    start = current - (maxpages // 2)
    if pagenum - start < maxpages:
        start = pagenum - maxpages
    if start <= 0:
        start = 1

    pages = []
    if pagenum > 1:
        if current >= 1:
            pages.append(
                {'page': '&larr;', 'skip': (1 - current) * plength, 'mover': True})
        else:
            pages.append({'page': '&larr;', 'skip': 0, 'mover': True})
        if start > 1:
            pages.append(
                {'page': '...', 'skip': (start - 1) * plength, 'mover': False})
            maxpages -= 1
        for i in range(start, pagenum + 1):
            if i > (maxpages + start + 1):
                pages.append(
                    {'page': '...', 'skip': (i) * plength, 'mover': False})
                break
            else:
                pages.append({'page': i, 'skip': (i - 1) * plength})
        if current + 1 == pagenum:
            pages.append(
                {'page': '&rarr;', 'skip': current * plength, 'mover': True})
        else:
            pages.append(
                {'page': '&rarr;', 'skip': (current + 1) * plength, 'mover': True})

    url = request.path + "?"
    if request.GET:
        for arg in request.GET:
            if arg != 'page_skip':
                values = request.GET.getlist(arg)
                for value in values:
                    url += unicode(arg) + "=" + value + "&"

    return Markup(render_to_string('core/tags/pager',
                                   {'url': url, 'pages': pages, 'skip': skip},
                                   response_format=response_format))
dataset/ETHPy150Open treeio/treeio/treeio/core/templatetags/modules.py/pager/swapped operands of `-`