<s> from django . template import Library <EOL> register = Library ( ) <EOL> DOT = '<STR_LIT:.>' <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def pagination ( context ) : <EOL> page_num = context [ '<STR_LIT>' ] . number - <NUM_LIT:1> <EOL> paginator = context [ '<STR_LIT:p>' ] <EOL> if not paginator . num_pages or paginator . num_pages == <NUM_LIT:1> : <EOL> page_range = [ ] <EOL> else : <EOL> ON_EACH_SIDE = <NUM_LIT:3> <EOL> ON_ENDS = <NUM_LIT:2> <EOL> if paginator . num_pages <= <NUM_LIT:10> : <EOL> page_range = range ( paginator . num_pages ) <EOL> else : <EOL> page_range = [ ] <EOL> if page_num > ( ON_EACH_SIDE + ON_ENDS ) : <EOL> page_range . extend ( range ( <NUM_LIT:0> , ON_EACH_SIDE - <NUM_LIT:1> ) ) <EOL> page_range . append ( DOT ) <EOL> page_range . extend ( range ( page_num - ON_EACH_SIDE , page_num + <NUM_LIT:1> ) ) <EOL> else : <EOL> page_range . extend ( range ( <NUM_LIT:0> , page_num + <NUM_LIT:1> ) ) <EOL> if page_num < ( paginator . num_pages - ON_EACH_SIDE - ON_ENDS - <NUM_LIT:1> ) : <EOL> page_range . extend ( range ( page_num + <NUM_LIT:1> , page_num + ON_EACH_SIDE + <NUM_LIT:1> ) ) <EOL> page_range . append ( DOT ) <EOL> page_range . extend ( range ( paginator . num_pages - ON_ENDS , paginator . num_pages ) ) <EOL> else : <EOL> page_range . extend ( range ( page_num + <NUM_LIT:1> , paginator . num_pages ) ) <EOL> return { <EOL> '<STR_LIT>' : page_range , <EOL> '<STR_LIT>' : page_num , <EOL> '<STR_LIT>' : context [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : context [ '<STR_LIT>' ] , <EOL> } </s>
