#NEWLINE# @ register . inclusion_tag ( 'rapidsms/templatetags/paginator.html' ) #NEWLINE# def paginator( objects ) : #NEWLINE# #INDENT# prefix = getattr ( objects , 'prefix' , '' ) #NEWLINE# dom_id = ( prefix + 'paginator' ) #NEWLINE# page_param = ( prefix + 'page' ) #NEWLINE# def _link( page_number ) : #NEWLINE# #INDENT# return _self_link ( objects . request , ** { #NEWLINE# #INDENT# page_param : page_number , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# def _page( number ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'number' : number , #NEWLINE# 'link' : _link ( number ) , #NEWLINE# 'active' : ( objects . number == number ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# max_page_links = settings . PAGINATOR_MAX_PAGE_LINKS #NEWLINE# last_page_number = ( objects . paginator . num_pages + 1 ) #NEWLINE# last_low_number = math . floor ( ( max_page_links / 2 ) ) #NEWLINE# first_high_number = ( last_page_number - math . ceil ( ( max_page_links / 2 ) ) ) #NEWLINE# page_links = [ _page ( number ) for number in range ( 1 , last_page_number ) if ( ( number <= last_low_number ) or ( number >= first_high_number ) ) ] #NEWLINE# if ( max_page_links < last_page_number ) : #NEWLINE# #INDENT# page_links . insert ( last_low_number , None ) #NEWLINE# #UNINDENT# subcontext = { #NEWLINE# #INDENT# 'dom_id' : objects , #NEWLINE# 'page_links' : page_links , #NEWLINE# #UNINDENT# } #NEWLINE# if ( objects . number > 1 ) : #NEWLINE# #INDENT# subcontext . update ( { #NEWLINE# #INDENT# 'first_page_link' : _link ( 1 ) , #NEWLINE# 'prev_page_link' : _link ( objects . previous_page_number ( ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( objects . number < objects . paginator . num_pages ) : #NEWLINE# #INDENT# subcontext . update ( { #NEWLINE# #INDENT# 'next_page_link' : _link ( objects . next_page_number ( ) ) , #NEWLINE# 'last_page_link' : _link ( objects . paginator . num_pages ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return subcontext