#NEWLINE# @ register . inclusion_tag ( 'datagrid/paginator.html' , takes_context = True ) #NEWLINE# def paginator( context , adjacent_pages = 3 ) : #NEWLINE# #INDENT# '\n    Renders a paginator used for jumping between pages of results.\n    ' #NEWLINE# page_nums = range ( max ( 1 , ( context [ 'page' ] - adjacent_pages ) ) , ( min ( context [ 'pages' ] , ( context [ 'page' ] + adjacent_pages ) ) + 1 ) ) #NEWLINE# getvars = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( 'request' in context ) : #NEWLINE# #INDENT# request = context [ 'request' ] #NEWLINE# getvars = request . GET . copy ( ) #NEWLINE# if ( 'page' in getvars ) : #NEWLINE# #INDENT# getvars [ 'page' ] #NEWLINE# #UNINDENT# #UNINDENT# getvars = urllib . urlencode ( getvars ) #NEWLINE# return { #NEWLINE# #INDENT# 'hits' : context [ 'hits' ] , #NEWLINE# 'results_per_page' : context [ 'results_per_page' ] , #NEWLINE# 'page' : context [ 'page' ] , #NEWLINE# 'pages' : context [ 'pages' ] , #NEWLINE# 'page_numbers' : page_nums , #NEWLINE# 'next' : context [ 'next' ] , #NEWLINE# 'previous' : context [ 'previous' ] , #NEWLINE# 'has_next' : context [ 'has_next' ] , #NEWLINE# 'has_previous' : context [ 'has_previous' ] , #NEWLINE# 'show_first' : ( 1 not in page_nums ) , #NEWLINE# 'show_last' : ( context [ 'pages' ] not in page_nums ) , #NEWLINE# 'extra_query' : context . get ( 'extra_query' , None ) , #NEWLINE# 'getvars' : getvars , #NEWLINE# #UNINDENT# }