def pages_to_show(paginator, page, pages_wanted=None, max_pages_wanted=9):
 page = int(page)
 page_precedence_order = [page, 1, paginator.num_pages, (page + 1), (page - 1), (page + 2), (page - 2), 2, (paginator.num_pages - 1)]
 if (pages_wanted is None):
  pages_wanted = []
 pages_wanted = (set(pages_wanted) or set(page_precedence_order[:max_pages_wanted]))
 pages_to_show = set(paginator.page_range).intersection(pages_wanted)
 pages_to_show = sorted(pages_to_show)
 skip_pages = [x[1] for x in zip(pages_to_show[:(-1)], pages_to_show[1:]) if ((x[1] - x[0]) != 1)]
 for i in skip_pages:
  pages_to_show.insert(pages_to_show.index(i), (-1))
 return pages_to_show

def pages_to_show ( paginator , page , pages_wanted = None , max_pages_wanted = 9 ) : page = int ( page ) page_precedence_order = [ page , 1 , paginator . num_pages , ( page + 1 ) , ( page - 1 ) , ( page + 2 ) , ( page - 2 ) , 2 , ( paginator . num_pages - 1 ) ] if ( pages_wanted is None ) : pages_wanted = [ ] pages_wanted = ( set ( pages_wanted ) or set ( page_precedence_order [ : max_pages_wanted ] ) ) pages_to_show = set ( paginator . page_range ) . intersection ( pages_wanted ) pages_to_show = sorted ( pages_to_show ) skip_pages = [ x [ 1 ] for x in zip ( pages_to_show [ : ( - 1 ) ] , pages_to_show [ 1 : ] ) if ( ( x [ 1 ] - x [ 0 ] ) != 1 ) ] for i in skip_pages : pages_to_show . insert ( pages_to_show . index ( i ) , ( - 1 ) ) return pages_to_show
function to select first two pages .