def delete_node(cur, node, auto_position=True): """ Delete node and its subtree. :param node: :type node: Node or int :param bool auto_position: See :ref:`coreapi-positioning` """ id = int(node) # Get Node object if integer (ID) was passed if auto_position and type(node) != NodeData: node = get_node(cur, id) sql = """ DELETE FROM nodes WHERE id=%s; """ cur.execute(sql, (id, )) if auto_position: shift_positions(cur, node.parent, node.position, -1)
def delete_node(cur, node, auto_position=True): """ Delete node and its subtree. :param node: :type node: Node or int :param bool auto_position: See :ref:`core-positioning` """ id = int(node) # Get Node object if integer (ID) was passed if auto_position and type(node) != NodeData: node = get_node(cur, id) sql = """ DELETE FROM nodes WHERE id=%s; """ cur.execute(sql, (id, )) if auto_position: shift_positions(cur, node.parent, node.position, -1)
def test_shift_positions_to_the_left(cur, root, nd1, nd2, nd3): shift_positions(cur, root, nd2.position, -1) assert get_node(cur, nd1.id).position == 0 assert get_node(cur, nd2.id).position == 1 assert get_node(cur, nd3.id).position == 3
def test_shift_positions_to_the_right(cur, root, nd1, nd2, nd3): shift_positions(cur, root, nd2.position, +1) assert get_node(cur, nd1.id).position == 0 assert get_node(cur, nd2.id).position == 2 assert get_node(cur, nd3.id).position == 4