Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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