<s> from django . core . paginator import Paginator , EmptyPage , InvalidPage <EOL> def paginated ( req , query_set , per_page = None , default_page = <NUM_LIT:1> , prefix = "<STR_LIT>" , wrapper = None ) : <EOL> if per_page is None : <EOL> from . . conf import settings <EOL> per_page = settings . PAGINATOR_OBJECTS_PER_PAGE <EOL> prefix = ( "<STR_LIT>" % ( prefix ) ) if prefix else "<STR_LIT>" <EOL> if ( prefix + "<STR_LIT>" ) in req . GET : <EOL> try : <EOL> per_page = int ( req . GET [ prefix + "<STR_LIT>" ] ) <EOL> except ValueError : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> ( req . GET [ prefix + "<STR_LIT>" ] ) ) <EOL> paginator = Paginator ( query_set , per_page ) <EOL> try : <EOL> if ( prefix + "<STR_LIT>" ) in req . GET : <EOL> page = int ( req . GET [ prefix + "<STR_LIT>" ] ) <EOL> else : <EOL> if default_page >= <NUM_LIT:0> : page = default_page <EOL> else : page = paginator . num_pages + ( default_page + <NUM_LIT:1> ) <EOL> objects = paginator . page ( page ) <EOL> except ( ValueError , EmptyPage , InvalidPage ) : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> ( req . GET [ prefix + "<STR_LIT>" ] ) ) <EOL> if wrapper is not None : <EOL> objects . raw_object_list = objects . object_list <EOL> objects . object_list = map ( wrapper , objects . object_list ) <EOL> objects . prefix = prefix <EOL> objects . request = req <EOL> return objects </s>
