Render paginator.
    <<_1_2 3 4 5 6 7 8 9 ... 55 56 57 >>  # leading=9 (1..9)  out=3 (55..57)
    << 1 2 3 ... 23 24 25 26_27_28 29 30 31 ... 55 56 57 >>  # adjacent = 4 (23..26, 28..31)

def paginator(context, page, leading=8, out=3, adjacent=3, sep='...'):
    """
    Render paginator.
    <<_1_2 3 4 5 6 7 8 9 ... 55 56 57 >>  # leading=9 (1..9)  out=3 (55..57)
    << 1 2 3 ... 23 24 25 26_27_28 29 30 31 ... 55 56 57 >>  # adjacent = 4 (23..26, 28..31)
    """
    leading_pages, out_left_pages, out_right_pages, pages = [], [], [], []
    num_pages = page.paginator.num_pages
    is_paginated = num_pages > 1
    if is_paginated:
        if num_pages < leading:
            leading_pages = [x for x in range(1, leading) if x <= num_pages]
        elif page.number <= leading - 1:
            leading_pages = [x for x in range(1, leading + 1)]
            out_right_pages = [x + num_pages for x in range(-out + 1, 1) if x + num_pages > leading]
        elif page.number > num_pages - leading + 1:
            leading_pages = [x for x in range(num_pages - leading + 1, num_pages + 1) if x <= num_pages]
            out_left_pages = [x for x in range(1, out + 1) if num_pages - x >= leading]
        else:
            leading_pages = [x for x in range(page.number - adjacent, page.number + adjacent + 1)]
            out_right_pages = [x + num_pages for x in range(-out + 1, 1)]
            out_left_pages = [x for x in range(1, out + 1)]
    if out_left_pages:
        pages.extend(out_left_pages)
        pages.append(sep)
    pages.extend(leading_pages)
    if out_right_pages:
        pages.append(sep)
        pages.extend(out_right_pages)
    return {
        'page': page,
        'pages': pages,
        'is_paginated': is_paginated,
        'separator': sep,
        'request': context.get('request'),
        'param_name': page.param_name if hasattr(page, 'param_name') else 'page',
    }