def _get_displayed_page_numbers(current, final):
 assert (current >= 1)
 assert (final >= current)
 if (final <= 5):
  return list(range(1, (final + 1)))
 included = {1, (current - 1), current, (current + 1), final}
 if (current <= 4):
  included.add(2)
  included.add(3)
 if (current >= (final - 3)):
  included.add((final - 1))
  included.add((final - 2))
 included = [idx for idx in sorted(list(included)) if ((idx > 0) and (idx <= final))]
 if (current > 4):
  included.insert(1, None)
 if (current < (final - 3)):
  included.insert((len(included) - 1), None)
 return included

def _get_displayed_page_numbers ( current , final ) : assert ( current >= 1 ) assert ( final >= current ) if ( final <= 5 ) : return list ( range ( 1 , ( final + 1 ) ) ) included = { 1 , ( current - 1 ) , current , ( current + 1 ) , final } if ( current <= 4 ) : included . add ( 2 ) included . add ( 3 ) if ( current >= ( final - 3 ) ) : included . add ( ( final - 1 ) ) included . add ( ( final - 2 ) ) included = [ idx for idx in sorted ( list ( included ) ) if ( ( idx > 0 ) and ( idx <= final ) ) ] if ( current > 4 ) : included . insert ( 1 , None ) if ( current < ( final - 3 ) ) : included . insert ( ( len ( included ) - 1 ) , None ) return included
this utility function determines a list of page numbers to display .