#NEWLINE# def table_context( request , table , links = None , paginate_by = None , page = None , extra_context = None , context_processors = None , paginator = None , show_hits = False , hit_label = 'Items' ) : #NEWLINE# #INDENT# '\n    :type table: Table\n    ' #NEWLINE# if ( extra_context is None ) : #NEWLINE# #INDENT# extra_context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# assert ( table . data is not None ) #NEWLINE# grouped_links = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( links is not None ) : #NEWLINE# #INDENT# links = evaluate_recursive ( links , table = table ) #NEWLINE# links = [ link for link in links if ( link . show and link . url ) ] #NEWLINE# grouped_links = groupby ( ( link for link in links if ( link . group is not None ) ) , key = ( lambda l : l . group ) ) #NEWLINE# grouped_links = [ ( g , slugify ( g ) , list ( lg ) ) for ( g , lg ) in grouped_links ] #NEWLINE# links = [ link for link in links if ( link . group is None ) ] #NEWLINE# #UNINDENT# base_context = { #NEWLINE# #INDENT# 'links' : links , #NEWLINE# 'grouped_links' : grouped_links , #NEWLINE# 'table' : table , #NEWLINE# #UNINDENT# } #NEWLINE# if paginate_by : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# paginate_by = int ( request . GET . get ( 'page_size' , paginate_by ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( paginator is None ) : #NEWLINE# #INDENT# paginator = Paginator ( table . data , paginate_by ) #NEWLINE# object_list = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# object_list = table . data #NEWLINE# #UNINDENT# if ( not page ) : #NEWLINE# #INDENT# page = request . GET . get ( 'page' , 1 ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# page = int ( page ) #NEWLINE# if ( page < 1 ) : #NEWLINE# #INDENT# page = 1 #NEWLINE# #UNINDENT# if ( page > paginator . num_pages ) : #NEWLINE# #INDENT# page = paginator . num_pages #NEWLINE# #UNINDENT# if ( object_list is None ) : #NEWLINE# #INDENT# table . data = paginator . page ( page ) . object_list #NEWLINE# #UNINDENT# #UNINDENT# except ( InvalidPage , ValueError ) : #NEWLINE# #INDENT# if ( page == 1 ) : #NEWLINE# #INDENT# table . data = [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Http404 #NEWLINE# #UNINDENT# #UNINDENT# base_context . update ( { #NEWLINE# #INDENT# 'request' : request , #NEWLINE# 'is_paginated' : ( paginator . num_pages > 1 ) , #NEWLINE# 'results_per_page' : paginate_by , #NEWLINE# 'has_next' : ( paginator . num_pages > page ) , #NEWLINE# 'has_previous' : ( page > 1 ) , #NEWLINE# 'page_size' : paginate_by , #NEWLINE# 'page' : page , #NEWLINE# 'next' : ( page + 1 ) , #NEWLINE# 'previous' : ( page - 1 ) , #NEWLINE# 'pages' : paginator . num_pages , #NEWLINE# 'hits' : paginator . count , #NEWLINE# 'show_hits' : show_hits , #NEWLINE# 'hit_label' : hit_label , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# base_context . update ( { #NEWLINE# #INDENT# 'is_paginated' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# base_context . update ( extra_context ) #NEWLINE# return RequestContext ( request , base_context , context_processors )