#NEWLINE# def get_page( self , object_list ) : #NEWLINE# #INDENT# '\n        Return a paginated object list, along with some metadata\n\n        If self.page_size is not None, pagination is enabled.\n\n        The page_size can be overridden by passing it in the requst, but it is\n        limited to 1 < page_size < max_page_size.\n\n        max_page_size defaults to self.page_size.\n\n        If a page_num is passed, it is fed to regular Django pagination\n        If an offset is passed, page_num is derived from it by dividing it by\n        page_size.\n\n        ' #NEWLINE# page_size = getattr ( self , 'page_size' , None ) #NEWLINE# if ( page_size is None ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'meta' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'objects' : object_list , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# max_page_size = getattr ( self , 'max_page_size' , page_size ) #NEWLINE# try : #NEWLINE# #INDENT# page_size = int ( self . request . GET . get ( self . LIMIT_PARAM , page_size ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise http . NotFound ( 'Invalid page size' ) #NEWLINE# #UNINDENT# page_size = max ( 1 , min ( page_size , max_page_size ) ) #NEWLINE# page_num = 0 #NEWLINE# try : #NEWLINE# #INDENT# page_num = int ( self . request . GET [ self . PAGE_PARAM ] ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# offset = int ( self . request . GET [ self . OFFSET_PARAM ] ) #NEWLINE# #UNINDENT# except ( ValueError , KeyError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# page_num = ( offset // page_size ) #NEWLINE# #UNINDENT# #UNINDENT# paginator = Paginator ( object_list , page_size , allow_empty_first_page = True ) #NEWLINE# try : #NEWLINE# #INDENT# page = paginator . page ( ( page_num + 1 ) ) #NEWLINE# #UNINDENT# except EmptyPage : #NEWLINE# #INDENT# raise http . NotFound ( ) #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'meta' : { #NEWLINE# #INDENT# 'offset' : ( page . start_index ( ) - 1 ) , #NEWLINE# 'page' : page_num , #NEWLINE# 'total_pages' : paginator . num_pages , #NEWLINE# 'limit' : page_size , #NEWLINE# 'count' : paginator . count , #NEWLINE# 'has_next' : page . has_next ( ) , #NEWLINE# 'has_prev' : page . has_previous ( ) , #NEWLINE# #UNINDENT# } , #NEWLINE# 'objects' : page . object_list , #NEWLINE# #UNINDENT# }