#NEWLINE# @ register . inclusion_tag ( 'paginator.html' , takes_context = True ) #NEWLINE# def paginator( context , adjacent_pages = 2 ) : #NEWLINE# #INDENT# '\n    To be used in conjunction with the object_list generic view.\n\n    Adds pagination context variables for use in displaying first, adjacent and\n    last page links in addition to those created by the object_list generic\n    view.\n\n    ' #NEWLINE# page_numbers = [ n for n in range ( ( context [ 'page' ] - adjacent_pages ) , ( ( context [ 'page' ] + query_dict ) + 1 ) ) if ( ( n > 0 ) and ( n <= context [ 'pages' ] ) ) ] #NEWLINE# path = context . get ( 'paginator_path_override' , context [ 'request' ] . path ) #NEWLINE# querystring = context [ 'request' ] . META . get ( 'QUERY_STRING' ) #NEWLINE# if ( not querystring ) : #NEWLINE# #INDENT# querystring = '' #NEWLINE# #UNINDENT# query_dict = dict ( cgi . parse_qsl ( querystring ) ) #NEWLINE# if ( 'page' in query_dict ) : #NEWLINE# #INDENT# del query_dict [ 'page' ] #NEWLINE# #UNINDENT# querystring = urllib . urlencode ( query_dict ) #NEWLINE# if querystring : #NEWLINE# #INDENT# path = ( '%s?%s&' % ( path , querystring ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# path = ( '%s?' % path ) #NEWLINE# #UNINDENT# 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_numbers , #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_numbers ) , #NEWLINE# 'show_last' : ( context [ 'pages' ] not in page_numbers ) , #NEWLINE# 'path' : path , #NEWLINE# #UNINDENT# }