#NEWLINE# def get_cached_row( row , index_start , using , klass_info , offset = 0 ) : #NEWLINE# #INDENT# '\n    Helper function that recursively returns an object with the specified\n    related attributes already populated.\n\n    This method may be called recursively to populate deep select_related()\n    clauses.\n\n    Arguments:\n         * row - the row of data returned by the database cursor\n         * index_start - the index of the row at which data for this\n           object is known to start\n         * offset - the number of additional fields that are known to\n           exist in row for `klass`. This usually means the number of\n           annotated results on `klass`.\n        * using - the database alias on which the query is being executed.\n         * klass_info - result of the get_klass_info function\n    ' #NEWLINE# if ( klass_info is None ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# ( klass , field_names , field_count , related_fields , reverse_related_fields , pk_idx ) = klass_info #NEWLINE# fields = row [ index_start : ( index_start + field_count ) ] #NEWLINE# if ( ( fields [ pk_idx ] == None ) or ( fields [ pk_idx ] == '' ) ) : #NEWLINE# #INDENT# obj = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if field_names : #NEWLINE# #INDENT# obj = klass ( ** dict ( zip ( field_names , fields ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj = klass ( * fields ) #NEWLINE# #UNINDENT# #UNINDENT# if obj : #NEWLINE# #INDENT# obj . _state . db = using #NEWLINE# obj . _state . adding = False #NEWLINE# #UNINDENT# index_end = ( ( index_start + field_count ) + offset ) #NEWLINE# for ( f , klass_info ) in related_fields : #NEWLINE# #INDENT# cached_row = get_cached_row ( row , index_end , using , klass_info ) #NEWLINE# if cached_row : #NEWLINE# #INDENT# ( rel_obj , index_end ) = cached_row #NEWLINE# if ( obj is not None ) : #NEWLINE# #INDENT# setattr ( obj , f . get_cache_name ( ) , rel_obj ) #NEWLINE# #UNINDENT# if ( f . unique and ( rel_obj is not None ) ) : #NEWLINE# #INDENT# setattr ( rel_obj , f . related . get_cache_name ( ) , obj ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for ( f , klass_info ) in reverse_related_fields : #NEWLINE# #INDENT# cached_row = get_cached_row ( row , index_end , using , klass_info ) #NEWLINE# if cached_row : #NEWLINE# #INDENT# ( rel_obj , index_end ) = cached_row #NEWLINE# if ( obj is not None ) : #NEWLINE# #INDENT# setattr ( obj , f . related . get_cache_name ( ) , rel_obj ) #NEWLINE# #UNINDENT# if ( rel_obj is not None ) : #NEWLINE# #INDENT# setattr ( rel_obj , f . get_cache_name ( ) , obj ) #NEWLINE# opts = rel_obj . _meta #NEWLINE# if getattr ( rel_obj , '_deferred' ) : #NEWLINE# #INDENT# opts = opts . proxy_for_model . _meta #NEWLINE# #UNINDENT# for ( rel_field , rel_model ) in opts . get_fields_with_model ( ) : #NEWLINE# #INDENT# if ( rel_model is not None ) : #NEWLINE# #INDENT# setattr ( rel_obj , rel_field . attname , getattr ( obj , rel_field . attname ) ) #NEWLINE# if rel_field . rel : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cached_obj = getattr ( obj , rel_field . get_cache_name ( ) ) #NEWLINE# setattr ( rel_obj , rel_field . get_cache_name ( ) , cached_obj ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( obj , index_end )