def paginated_list(object_list, page, page_size=<NUM_LIT>):
paginator = CustomPaginator(object_list, page_size)<EOL>try:<EOL><INDENT>object_list = paginator.page(page)<EOL><DEDENT>except PageNotAnInteger:<EOL><INDENT>object_list = paginator.page(<NUM_LIT:1>)<EOL><DEDENT>except EmptyPage:<EOL><INDENT>object_list = paginator.page(paginator.num_pages)<EOL><DEDENT>page_range = []<EOL>page_num = object_list.number<EOL>if paginator.num_pages <= <NUM_LIT:10>:<EOL><INDENT>page_range = range(paginator.num_pages)<EOL><DEDENT>else:<EOL><INDENT>if page_num > (PAGES_ON_EACH_SIDE + PAGES_ON_ENDS + <NUM_LIT:1>):<EOL><INDENT>page_range.extend(range(<NUM_LIT:1>, PAGES_ON_ENDS + <NUM_LIT:1>))<EOL>page_range.append(DOT)<EOL>page_range.extend(range(page_num - PAGES_ON_EACH_SIDE, page_num + <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>page_range.extend(range(<NUM_LIT:1>, page_num + <NUM_LIT:1>))<EOL><DEDENT>if page_num < (paginator.num_pages - PAGES_ON_EACH_SIDE - PAGES_ON_ENDS):<EOL><INDENT>page_range.extend(range(page_num + <NUM_LIT:1>, page_num + PAGES_ON_EACH_SIDE + <NUM_LIT:1>))<EOL>page_range.append(DOT)<EOL>page_range.extend(range(paginator.num_pages + <NUM_LIT:1> - PAGES_ON_ENDS, paginator.num_pages + <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>page_range.extend(range(page_num + <NUM_LIT:1>, paginator.num_pages + <NUM_LIT:1>))<EOL><DEDENT>object_list.paginator.page_range = page_range<EOL><DEDENT>return object_list<EOL>
Returns paginated list.

Arguments:
    object_list (QuerySet): A list of records to be paginated.
    page (int): Current page number.
    page_size (int): Number of records displayed in each paginated set.
    show_all (bool): Whether to show all records.

Adopted from django/contrib/admin/templatetags/admin_list.py
https://github.com/django/django/blob/1.11.1/django/contrib/admin/templatetags/admin_list.py#L50