Beispiel #1
0
def create_nodes_for_path(path, authors=()):
    nodes, last = parse_path(path)
    current_node = get_root_node()
    current_path = ""
    for short_title, index in nodes:
        # slot
        current_path += '/' + short_title
        try:
            current_slot = get_node_for_path(current_path)
        except IllegalPath:
            current_slot = create_slot(short_title)
            current_node.append_child(current_slot)

        # alternatives
        current_path += '.' + str(index)
        try:
            current_node = get_node_for_path(current_path)
        except IllegalPath:
            if current_slot.child_order_set.count() == 0:
                highest_index = 0
            else:
                highest_index = current_slot.child_order_set.order_by(
                    'position')[0].position

            for i in range(highest_index, index):
                current_node = create_structureNode(short_title + '_long',
                                                    authors=authors)
                current_slot.append_child(current_node)

    return current_node
Beispiel #2
0
def get_node_for_path(path):
    """
    Return the node corresponding node to the given path.
    """
    node = get_root_node()
    layers, last = parse_path(path)
    for title, pos_id in layers:
        children = node.children.filter(title=title).all()
        if len(children) != 1:
            raise IllegalPath(path)
        else:
            order = NodeOrder.objects.filter(parent__in=children).\
                                      filter(position=pos_id).prefetch_related('child').all()
            if len(order) != 1:
                raise IllegalPath(path)
            else:
                node = order[0].child
    if 'slot' in last:
        children = node.children.filter(title=last['slot']).all()
        if len(children) != 1:
            raise IllegalPath(path)
        else:
            node = children[0]
    elif 'arg_type' in last and 'arg_id' in last:
        argument_order = ArgumentOrder.objects.filter(node=node).\
                                     filter(position=last['arg_id']).prefetch_related('argument').all()
        if len(argument_order) != 1:
            raise IllegalPath(path)
        else:
            node = argument_order[0].argument
    return node
Beispiel #3
0
def create_nodes_for_path(path, authors=()):
    nodes, last = parse_path(path)
    current_node = get_root_node()
    current_path = ""
    for short_title, index in nodes:
        # slot
        current_path += '/' + short_title
        try:
            current_slot = get_node_for_path(current_path)
        except IllegalPath:
            current_slot = create_slot(short_title)
            current_node.append_child(current_slot)

        # alternatives
        current_path += '.' + str(index)
        try:
            current_node = get_node_for_path(current_path)
        except IllegalPath:
            if current_slot.child_order_set.count() == 0:
                highest_index = 0
            else:
                highest_index = current_slot.child_order_set.order_by(
                    'position')[0].position

            for i in range(highest_index, index):
                current_node = create_structureNode(short_title + '_long',
                                                    authors=authors)
                current_slot.append_child(current_node)

    return current_node