#NEWLINE# def _move_root_node( self , node , target , position ) : #NEWLINE# #INDENT# '\n        Moves root node``node`` to a different tree, inserting it\n        relative to the given ``target`` node as specified by\n        ``position``.\n\n        ``node`` will be modified to reflect its new tree state in the\n        database.\n        ' #NEWLINE# left = getattr ( node , self . left_attr ) #NEWLINE# right = getattr ( node , self . right_attr ) #NEWLINE# level = getattr ( node , self . level_attr ) #NEWLINE# tree_id = getattr ( node , self . tree_id_attr ) #NEWLINE# new_tree_id = getattr ( target , self . tree_id_attr ) #NEWLINE# width = ( ( right - left ) + 1 ) #NEWLINE# if ( node == target ) : #NEWLINE# #INDENT# raise InvalidMove ( _ ( 'A node may not be made a child of itself.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tree_id == new_tree_id ) : #NEWLINE# #INDENT# raise InvalidMove ( _ ( 'A node may not be made a child of any of its descendants.' ) ) #NEWLINE# #UNINDENT# #UNINDENT# ( space_target , level_change , left_right_change , parent ) = self . _calculate_inter_tree_move_values ( node , target , position ) #NEWLINE# self . _create_space ( width , space_target , new_tree_id ) #NEWLINE# opts = self . model . _meta #NEWLINE# move_tree_query = ( '\n        UPDATE %(table)s\n        SET %(level)s = %(level)s - %%s,\n            %(left)s = %(left)s - %%s,\n            %(right)s = %(right)s - %%s,\n            %(tree_id)s = %%s,\n            %(parent)s = CASE\n                WHEN %(pk)s = %%s\n                    THEN %%s\n                ELSE %(parent)s END\n        WHERE %(left)s >= %%s AND %(left)s <= %%s\n          AND %(tree_id)s = %%s' % { #NEWLINE# #INDENT# 'table' : qn ( opts . db_table ) , #NEWLINE# 'level' : qn ( opts . get_field ( self . level_attr ) . column ) , #NEWLINE# 'left' : qn ( opts . get_field ( self . left_attr ) . column ) , #NEWLINE# 'right' : qn ( opts . get_field ( self . right_attr ) . column ) , #NEWLINE# 'tree_id' : qn ( opts . get_field ( self . tree_id_attr ) . column ) , #NEWLINE# 'parent' : qn ( opts . get_field ( self . parent_attr ) . column ) , #NEWLINE# 'pk' : qn ( opts . pk . column ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# cursor = connection . cursor ( ) #NEWLINE# cursor . execute ( move_tree_query , [ level_change , left_right_change , left_right_change , new_tree_id , node . pk , parent . pk , left , right , tree_id ] ) #NEWLINE# setattr ( node , self . left_attr , ( left - left_right_change ) ) #NEWLINE# setattr ( node , self . right_attr , ( right - left_right_change ) ) #NEWLINE# setattr ( node , self . level_attr , ( level - level_change ) ) #NEWLINE# setattr ( node , self . tree_id_attr , new_tree_id ) #NEWLINE# setattr ( node , self . parent_attr , parent )