<s> import sqlalchemy <EOL> class TreeClassManager ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , node_class , options ) : <EOL> self . _tree_options = options <EOL> self . _node_class = node_class <EOL> def __clause_element__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _tree_options . order_by_clause ( ) <EOL> def filter_root_nodes ( self ) : <EOL> "<STR_LIT>" <EOL> options = self . _tree_options <EOL> return options . left_field == <NUM_LIT:1> <EOL> def query_root_nodes ( self , session = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if session is None : <EOL> session = sqlalchemy . orm . object_session ( self . _get_obj ( ) ) <EOL> return session . query ( self . _node_class ) . filter ( self . filter_root_nodes ( * args , ** kwargs ) ) <EOL> def filter_root_node_by_tree_id ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> return self . filter_root_nodes ( ) & options . tree_id_field . in_ ( args ) <EOL> def query_root_node_by_tree_id ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> session = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if session is None : <EOL> session = sqlalchemy . orm . object_session ( self . _get_obj ( ) ) <EOL> return session . query ( self . _node_class ) . filter ( self . filter_root_node_by_tree_id ( * args , ** kwargs ) ) <EOL> def filter_root_node_of_node ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> return self . filter_root_nodes ( ) & options . tree_id_field . in_ ( <EOL> map ( lambda n : getattr ( n , options . tree_id_field . name ) , args ) ) <EOL> def query_root_node_of_node ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> session = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if session is None : <EOL> for node in args : <EOL> session = sqlalchemy . orm . object_session ( node ) <EOL> if session is not None : <EOL> break <EOL> if session is None : <EOL> session <EOL> session = sqlalchemy . orm . object_session ( self . _get_obj ( ) ) <EOL> return session . query ( self . _node_class ) . filter ( self . filter_root_node_of_node ( * args , ** kwargs ) ) <EOL> POSITION_LEFT = '<STR_LIT:left>' <EOL> POSITION_RIGHT = '<STR_LIT:right>' <EOL> POSITION_FIRST_CHILD = '<STR_LIT>' <EOL> POSITION_LAST_CHILD = '<STR_LIT>' <EOL> def insert_node ( self , node , target = None , position = POSITION_LAST_CHILD , session = None ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> if session is None : <EOL> if target is not None : <EOL> session = sqlalchemy . orm . object_session ( target ) <EOL> else : <EOL> session = sqlalchemy . orm . object_session ( node ) <EOL> pk = getattr ( node , options . pk_field . name ) <EOL> if pk is not None and session . query ( self . _node_class ) . filter ( options . pk_field == pk ) . limit ( <NUM_LIT:1> ) . count ( ) : <EOL> raise ValueError ( <EOL> _ ( u"<STR_LIT>" u"<STR_LIT>" ) ) <EOL> if target is None : <EOL> setattr ( node , options . parent_id_field . name , None ) <EOL> setattr ( node , options . tree_id_field . name , self . _get_next_tree_id ( session ) ) <EOL> setattr ( node , options . left_field . name , <NUM_LIT:1> ) <EOL> setattr ( node , options . right_field . name , <NUM_LIT:2> ) <EOL> setattr ( node , options . depth_field . name , <NUM_LIT:0> ) <EOL> elif getattr ( target , options . parent_id_field . name ) is None and position in [ self . POSITION_LEFT , self . POSITION_RIGHT ] : <EOL> target_tree_id = getattr ( target , options . tree_id_field . name ) <EOL> if position == self . POSITION_LEFT : <EOL> node_tree_id = target_tree_id <EOL> target_tree_id = target_tree_id - <NUM_LIT:1> <EOL> else : <EOL> node_tree_id = target_tree_id + <NUM_LIT:1> <EOL> self . _manage_tree_gap ( <NUM_LIT:1> , target_tree_id , session ) <EOL> setattr ( node , options . parent_id_field . name , None ) <EOL> setattr ( node , options . tree_id_field . name , node_tree_id ) <EOL> setattr ( node , options . left_field . name , <NUM_LIT:1> ) <EOL> setattr ( node , options . right_field . name , <NUM_LIT:2> ) <EOL> setattr ( node , options . depth_field . name , <NUM_LIT:0> ) <EOL> else : <EOL> setattr ( node , options . left_field . name , <NUM_LIT:0> ) <EOL> setattr ( node , options . right_field . name , <NUM_LIT:1> ) <EOL> setattr ( node , options . depth_field . name , <NUM_LIT:0> ) <EOL> gap_target , depth , left , parent , right_shift = self . _calculate_inter_tree_move_values ( node , target , position , session ) <EOL> if parent is None : <EOL> parent_id = None <EOL> tree_id = None <EOL> else : <EOL> parent_id = getattr ( parent , options . pk_field . name ) <EOL> tree_id = getattr ( parent , options . tree_id_field . name ) <EOL> self . _create_gap ( right_shift , gap_target , tree_id , session ) <EOL> setattr ( node , options . left_field . name , left ) <EOL> setattr ( node , options . right_field . name , left + <NUM_LIT:1> ) <EOL> setattr ( node , options . depth_field . name , depth ) <EOL> setattr ( node , options . tree_id_field . name , tree_id ) <EOL> setattr ( node , options . parent_id_field . name , parent_id ) <EOL> def _get_next_tree_id ( self , session ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> return session . query ( ( <EOL> sqlalchemy . func . max ( options . tree_id_field ) + <NUM_LIT:1> ) . label ( '<STR_LIT>' ) ) . all ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] or <NUM_LIT:1> <EOL> def _manage_tree_gap ( self , size , target_tree_id , session ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> expr = options . table . update ( ) . values ( { options . tree_id_field . name : options . tree_id_field + size } ) . where ( options . tree_id_field > target_tree_id ) <EOL> session . execute ( expr ) <EOL> def _manage_space ( self , size , target , tree_id , session ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> expr = options . table . update ( ) . values ( { <EOL> options . left_field : sqlalchemy . case ( <EOL> [ ( options . left_field > target , options . left_field + size ) ] , <EOL> else_ = options . left_field ) , <EOL> options . right_field : sqlalchemy . case ( <EOL> [ ( options . right_field > target , options . right_field + size ) ] , <EOL> else_ = options . right_field ) , <EOL> } ) . where ( <EOL> ( options . tree_id_field == tree_id ) & <EOL> ( ( options . left_field > target ) | <EOL> ( options . right_field > target ) ) <EOL> ) <EOL> session . execute ( expr ) <EOL> def _create_gap ( self , size , target , tree_id , session ) : <EOL> """<STR_LIT>""" <EOL> self . _manage_space ( size , target , tree_id , session ) <EOL> def _close_gap ( self , size , target , tree_id , session ) : <EOL> """<STR_LIT>""" <EOL> self . _manage_space ( - size , target , tree_id , session ) <EOL> def _calculate_inter_tree_move_values ( self , node , target , position , session ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> node_left = getattr ( node , options . left_field . name ) <EOL> node_right = getattr ( node , options . right_field . name ) <EOL> node_depth = getattr ( node , options . depth_field . name ) <EOL> target_left = getattr ( target , options . left_field . name ) <EOL> target_right = getattr ( target , options . right_field . name ) <EOL> target_depth = getattr ( target , options . depth_field . name ) <EOL> if position == self . POSITION_LAST_CHILD or position == self . POSITION_FIRST_CHILD : <EOL> if position == self . POSITION_LAST_CHILD : <EOL> gap_target = target_right - <NUM_LIT:1> <EOL> else : <EOL> gap_target = target_left <EOL> depth_change = target_depth - node_depth + <NUM_LIT:1> <EOL> parent = target <EOL> elif position == self . POSITION_LEFT or position == self . POSITION_RIGHT : <EOL> if position == self . POSITION_LEFT : <EOL> gap_target = target_left - <NUM_LIT:1> <EOL> else : <EOL> gap_target = target_right <EOL> depth_change = target_depth - node_depth <EOL> parent = getattr ( target , options . parent_id_field . name ) <EOL> if parent : <EOL> parent = session . query ( self . _node_class ) . filter ( options . pk_field == parent ) . one ( ) <EOL> else : <EOL> raise ValueError ( _ ( u"<STR_LIT>" ) % position ) <EOL> left_right_change = gap_target - node_left + <NUM_LIT:1> <EOL> right_shift = <NUM_LIT:0> <EOL> if parent : <EOL> right_shift = node_right - node_left + <NUM_LIT:1> <EOL> return gap_target , depth_change , left_right_change , parent , right_shift <EOL> def move_node ( self , node , target , position = POSITION_LAST_CHILD , session = None ) : <EOL> """<STR_LIT>""" <EOL> if session is None : <EOL> session = sqlalchemy . orm . object_session ( node ) <EOL> """<STR_LIT>""" <EOL> def _inter_tree_move_and_close_gap ( self , node , depth_change , <EOL> left_right_change , new_tree_id , parent_pk = None ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> inter_tree_move_query = """<STR_LIT>""" % { <EOL> '<STR_LIT>' : qn ( self . tree_model . _meta . db_table ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . depth_field . name ) . column ) , <EOL> '<STR_LIT:left>' : qn ( opts . get_field ( options . left_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . tree_id_field . name ) . column ) , <EOL> '<STR_LIT:right>' : qn ( opts . get_field ( options . right_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . parent_id_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . pk . column ) , <EOL> '<STR_LIT>' : parent_pk is None and '<STR_LIT>' or '<STR_LIT:%s>' , <EOL> } <EOL> left = getattr ( node , options . left_field . name ) <EOL> right = getattr ( node , options . right_field . name ) <EOL> gap_size = right - left + <NUM_LIT:1> <EOL> gap_target_left = left - <NUM_LIT:1> <EOL> params = [ <EOL> left , right , depth_change , <EOL> left , right , new_tree_id , <EOL> left , right , left_right_change , <EOL> gap_target_left , gap_size , <EOL> left , right , left_right_change , <EOL> gap_target_left , gap_size , <EOL> node . pk , <EOL> getattr ( node , options . tree_id_field . name ) <EOL> ] <EOL> if parent_pk is not None : <EOL> params . insert ( - <NUM_LIT:1> , parent_pk ) <EOL> cursor = self . _get_connection ( node ) . cursor ( ) <EOL> cursor . execute ( inter_tree_move_query , params ) <EOL> def _make_child_root_node ( self , node , new_tree_id = None ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> left = getattr ( node , options . left_field . name ) <EOL> right = getattr ( node , options . right_field . name ) <EOL> depth = getattr ( node , options . depth_field . name ) <EOL> if not new_tree_id : <EOL> new_tree_id = self . _get_next_tree_id ( ) <EOL> left_right_change = left - <NUM_LIT:1> <EOL> self . _inter_tree_move_and_close_gap ( node , level , left_right_change , <EOL> new_tree_id ) <EOL> setattr ( node , options . left_field . name , left - left_right_change ) <EOL> setattr ( node , options . right_field . name , right - left_right_change ) <EOL> setattr ( node , options . depth_field . name , <NUM_LIT:0> ) <EOL> setattr ( node , options . tree_id_field . name , new_tree_id ) <EOL> setattr ( node , options . parent_id_field . name , None ) <EOL> node . _mptt_cached_fields [ options . parent_id_field . name ] = None <EOL> def _make_sibling_of_root_node ( self , node , target , position ) : <EOL> """<STR_LIT>""" <EOL> if node == target : <EOL> raise InvalidMoveError ( _ ( '<STR_LIT>' ) ) <EOL> opts = self . model . _meta <EOL> tree_id = getattr ( node , options . tree_id_field . name ) <EOL> target_tree_id = getattr ( target , options . tree_id_field . name ) <EOL> if node . is_child_node ( ) : <EOL> if position == self . POSITION_LEFT : <EOL> gap_target = target_tree_id - <NUM_LIT:1> <EOL> new_tree_id = target_tree_id <EOL> elif position == self . POSITION_RIGHT : <EOL> gap_target = target_tree_id <EOL> new_tree_id = target_tree_id + <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( _ ( '<STR_LIT>' ) % position ) <EOL> self . _manage_tree_gap ( <NUM_LIT:1> , gap_target , session ) <EOL> if tree_id > gap_target : <EOL> setattr ( node , options . tree_id_field . name , tree_id + <NUM_LIT:1> ) <EOL> self . _make_child_root_node ( node , new_tree_id ) <EOL> else : <EOL> if position == self . POSITION_LEFT : <EOL> if target_tree_id > tree_id : <EOL> left_sibling = target . get_previous_sibling ( ) <EOL> if node == left_sibling : <EOL> return <EOL> new_tree_id = getattr ( left_sibling , options . tree_id_field . name ) <EOL> lower_bound , upper_bound = tree_id , new_tree_id <EOL> shift = - <NUM_LIT:1> <EOL> else : <EOL> new_tree_id = target_tree_id <EOL> lower_bound , upper_bound = new_tree_id , tree_id <EOL> shift = <NUM_LIT:1> <EOL> elif position == self . POSITION_RIGHT : <EOL> if target_tree_id > tree_id : <EOL> new_tree_id = target_tree_id <EOL> lower_bound , upper_bound = tree_id , target_tree_id <EOL> shift = - <NUM_LIT:1> <EOL> else : <EOL> right_sibling = target . get_next_sibling ( ) <EOL> if node == right_sibling : <EOL> return <EOL> new_tree_id = getattr ( right_sibling , options . tree_id_field . name ) <EOL> lower_bound , upper_bound = new_tree_id , tree_id <EOL> shift = <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( _ ( '<STR_LIT>' ) % position ) <EOL> root_sibling_query = """<STR_LIT>""" % { <EOL> '<STR_LIT>' : qn ( self . tree_model . _meta . db_table ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . tree_id_field . name ) . column ) , <EOL> } <EOL> cursor = self . _get_connection ( node ) . cursor ( ) <EOL> cursor . execute ( root_sibling_query , [ tree_id , new_tree_id , shift , <EOL> lower_bound , upper_bound ] ) <EOL> setattr ( node , options . tree_id_field . name , new_tree_id ) <EOL> def _move_child_node ( self , node , target , position ) : <EOL> """<STR_LIT>""" <EOL> tree_id = getattr ( node , options . tree_id_field . name ) <EOL> target_tree_id = getattr ( target , options . tree_id_field . name ) <EOL> if tree_id == target_tree_id : <EOL> self . _move_child_within_tree ( node , target , position ) <EOL> else : <EOL> self . _move_child_to_new_tree ( node , target , position ) <EOL> def _move_child_to_new_tree ( self , node , target , position ) : <EOL> """<STR_LIT>""" <EOL> left = getattr ( node , options . left_field . name ) <EOL> right = getattr ( node , options . right_field . name ) <EOL> depth = getattr ( node , options . depth_field . name ) <EOL> new_tree_id = getattr ( target , options . tree_id_field . name ) <EOL> gap_target , depth_change , left_right_change , parent , new_parent_right = self . _calculate_inter_tree_move_values ( node , target , position , session ) <EOL> tree_width = right - left + <NUM_LIT:1> <EOL> self . _create_gap ( tree_width , gap_target , new_tree_id , session ) <EOL> self . _inter_tree_move_and_close_gap ( node , depth_change , <EOL> left_right_change , new_tree_id , parent . pk ) <EOL> setattr ( node , options . left_field . name , left - left_right_change ) <EOL> setattr ( node , options . right_field . name , right - left_right_change ) <EOL> setattr ( node , options . depth_field . name , depth - depth_change ) <EOL> setattr ( node , options . tree_id_field . name , new_tree_id ) <EOL> setattr ( node , options . parent_id_field . name , parent ) <EOL> node . _mptt_cached_fields [ options . parent_id_field . name ] = parent . pk <EOL> def _move_child_within_tree ( self , node , target , position ) : <EOL> """<STR_LIT>""" <EOL> left = getattr ( node , options . left_field . name ) <EOL> right = getattr ( node , options . right_field . name ) <EOL> depth = getattr ( node , options . depth_field . name ) <EOL> width = right - left + <NUM_LIT:1> <EOL> tree_id = getattr ( node , options . tree_id_field . name ) <EOL> target_left = getattr ( target , options . left_field . name ) <EOL> target_right = getattr ( target , options . right_field . name ) <EOL> target_depth = getattr ( target , options . depth_field . name ) <EOL> if position == self . POSITION_LAST_CHILD or position == self . POSITION_RIGHT : <EOL> if node == target : <EOL> raise InvalidMoveError ( _ ( '<STR_LIT>' ) ) <EOL> elif left < target_left < right : <EOL> raise InvalidMoveError ( _ ( '<STR_LIT>' ) ) <EOL> if position == self . POSITION_LAST_CHILD : <EOL> if target_right > right : <EOL> new_left = target_right - width <EOL> new_right = target_right - <NUM_LIT:1> <EOL> else : <EOL> new_left = target_right <EOL> new_right = target_right + width - <NUM_LIT:1> <EOL> else : <EOL> if target_left > left : <EOL> new_left = target_left - width + <NUM_LIT:1> <EOL> new_right = target_left <EOL> else : <EOL> new_left = target_left + <NUM_LIT:1> <EOL> new_right = target_left + width <EOL> depth_change = depth - target_depth - <NUM_LIT:1> <EOL> parent = target <EOL> elif position == self . POSITION_LEFT or position == self . POSITION_RIGHT : <EOL> if node == target : <EOL> raise InvalidMove ( _ ( '<STR_LIT>' ) ) <EOL> elif left < target_left < right : <EOL> raise InvalidMove ( _ ( '<STR_LIT>' ) ) <EOL> if position == self . POSITION_LEFT : <EOL> if target_left > left : <EOL> new_left = target_left - width <EOL> new_right = target_left - <NUM_LIT:1> <EOL> else : <EOL> new_left = target_left <EOL> new_right = target_left + width - <NUM_LIT:1> <EOL> else : <EOL> if target_right > right : <EOL> new_left = target_right - width + <NUM_LIT:1> <EOL> new_right = target_right <EOL> else : <EOL> new_left = target_right + <NUM_LIT:1> <EOL> new_right = target_right + width <EOL> depth_change = depth - target_depth <EOL> parent = getattr ( target , options . parent_id_field . name ) <EOL> else : <EOL> raise ValueError ( _ ( '<STR_LIT>' ) % position ) <EOL> left_boundary = min ( left , new_left ) <EOL> right_boundary = max ( right , new_right ) <EOL> left_right_change = new_left - left <EOL> gap_size = width <EOL> if left_right_change > <NUM_LIT:0> : <EOL> gap_size = - gap_size <EOL> opts = self . model . _meta <EOL> move_subtree_query = """<STR_LIT>""" % { <EOL> '<STR_LIT>' : qn ( self . tree_model . _meta . db_table ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . depth_field . name ) . column ) , <EOL> '<STR_LIT:left>' : qn ( opts . get_field ( options . left_field . name ) . column ) , <EOL> '<STR_LIT:right>' : qn ( opts . get_field ( options . right_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . parent_id_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . pk . column ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . tree_id_field . name ) . column ) , <EOL> } <EOL> cursor = self . _get_connection ( node ) . cursor ( ) <EOL> cursor . execute ( move_subtree_query , [ <EOL> left , right , depth_change , <EOL> left , right , left_right_change , <EOL> left_boundary , right_boundary , gap_size , <EOL> left , right , left_right_change , <EOL> left_boundary , right_boundary , gap_size , <EOL> node . pk , parent . pk , <EOL> tree_id ] ) <EOL> setattr ( node , options . left_field . name , new_left ) <EOL> setattr ( node , options . right_field . name , new_right ) <EOL> setattr ( node , options . depth_field . name , depth - depth_change ) <EOL> setattr ( node , options . parent_id_field . name , parent ) <EOL> node . _mptt_cached_fields [ options . parent_id_field . name ] = parent . pk <EOL> def _move_root_node ( self , node , target , position ) : <EOL> """<STR_LIT>""" <EOL> left = getattr ( node , options . left_field . name ) <EOL> right = getattr ( node , options . right_field . name ) <EOL> depth = getattr ( node , options . depth_field . name ) <EOL> tree_id = getattr ( node , options . tree_id_field . name ) <EOL> new_tree_id = getattr ( target , options . tree_id_field . name ) <EOL> width = right - left + <NUM_LIT:1> <EOL> if node == target : <EOL> raise InvalidMove ( _ ( '<STR_LIT>' ) ) <EOL> elif tree_id == new_tree_id : <EOL> raise InvalidMove ( _ ( '<STR_LIT>' ) ) <EOL> gap_target , depth_change , left_right_change , parent , right_shift = self . _calculate_inter_tree_move_values ( node , target , position , session ) <EOL> self . _create_gap ( width , gap_target , new_tree_id , session ) <EOL> opts = self . model . _meta <EOL> move_tree_query = """<STR_LIT>""" % { <EOL> '<STR_LIT>' : qn ( self . tree_model . _meta . db_table ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . depth_field . name ) . column ) , <EOL> '<STR_LIT:left>' : qn ( opts . get_field ( options . left_field . name ) . column ) , <EOL> '<STR_LIT:right>' : qn ( opts . get_field ( options . right_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . tree_id_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . get_field ( options . parent_id_field . name ) . column ) , <EOL> '<STR_LIT>' : qn ( opts . pk . column ) , <EOL> } <EOL> cursor = self . _get_connection ( node ) . cursor ( ) <EOL> cursor . execute ( move_tree_query , [ depth_change , left_right_change , <EOL> left_right_change , new_tree_id , node . pk , parent . pk , left , right , <EOL> tree_id ] ) <EOL> setattr ( node , options . left_field . name , left - left_right_change ) <EOL> setattr ( node , options . right_field . name , right - left_right_change ) <EOL> setattr ( node , options . depth_field . name , depth - depth_change ) <EOL> setattr ( node , options . tree_id_field . name , new_tree_id ) <EOL> setattr ( node , options . parent_id_field . name , parent ) <EOL> node . _mptt_cached_fields [ options . parent_id_field . name ] = parent . pk <EOL> def _do_rebuild_subtree ( self , root_node_id , root_path , root_depth , tree_id , order_by ) : <EOL> """<STR_LIT>""" <EOL> options = self . _tree_options <EOL> path = root_path + ALPHABET [ <NUM_LIT:0> ] * options . steplen <EOL> depth = root_depth + <NUM_LIT:1> <EOL> children = sqlalchemy . select ( <EOL> [ options . pk_field ] , <EOL> options . parent_id_field == root_node_id <EOL> ) . order_by ( order_by ) <EOL> query = options . table . update ( ) <EOL> for child in children . execute ( ) . fetchall ( ) : <EOL> [ child ] = child <EOL> query . where ( options . pk_field == child ) . values ( { options . path_field : path , options . depth_field : depth , options . tree_id_field : tree_id } ) . execute ( ) <EOL> self . _do_rebuild_subtree ( child , path , depth , tree_id , order_by ) <EOL> path = inc_path ( path , options . steplen ) </s>
