Ejemplo n.º 1
0
def fork_node_and_add_slot(path, user, wiki_text):
    source_node = assert_node_for_path(path)
    authors = list(source_node.text.authors.all()) + [user]
    title = source_node.title
    # create fork
    fork = create_structureNode(title,
                                source_node.text.text,
                                authors)
    parent_slot_path = path.rsplit('.', 1)[0]
    parent_slot = get_node_for_path(parent_slot_path)
    parent_slot.append_child(fork)
    fork_path = parent_slot_path + '.' + str(fork.get_index(parent_slot))
    short_titles = set()
    for slot in get_ordered_children_for(source_node):
        fork.append_child(slot)
        short_titles.add(slot.title)
    # create new slot plus node
    schema = parse(wiki_text, 'foo')
    short_title = turn_into_valid_short_title(schema['title'], short_titles)
    new_slot = create_slot(short_title)
    fork.append_child(new_slot)
    node = create_structure_from_structure_node_schema(schema, new_slot, user)
    arg_title = "Abschnitt über '{0}' fehlt.".format(schema['title'])
    source_node.add_derivate(fork, 'con', arg_title, authors=[user])
    # auto follow
    follow_node(fork, user.id)
    follow_node(node, user.id)
    return fork_path
Ejemplo n.º 2
0
def create_topic(src_path, topic_name):
    print("Creating '%s' from file '%s'." % (topic_name, src_path))
    root = get_root_node()
    decided = User.objects.get(username="******")
    slot = create_slot(topic_name)
    root.append_child(slot)
    with open(src_path, 'r') as src:
        schema = parse(unicode(src.read(), encoding='utf-8'), slot.title)
        create_structure_from_structure_node_schema(schema, slot, decided)
Ejemplo n.º 3
0
def create_topic(src_path, topic_name):
        print("Creating '%s' from file '%s'." % (topic_name, src_path))
        root = get_root_node()
        decided = User.objects.get(username="******")
        slot = create_slot(topic_name)
        root.append_child(slot)
        with open(src_path, 'r') as src:
            schema = parse(unicode(src.read(), encoding='utf-8'), slot.title)
            create_structure_from_structure_node_schema(schema, slot, decided)
Ejemplo n.º 4
0
def store_structure_node(path, wiki_text, author):
    slot_path = path.rsplit('.', 1)[0]
    slot = get_node_for_path(slot_path)
    structure = backend.parse(wiki_text, None)
    structure_node = backend.create_structure_from_structure_node_schema(
        structure, slot, [author])
    # add auto follow
    create_vote(author, [structure_node])
    return structure_node, get_good_path_for_structure_node(structure_node,
                                                            slot, slot_path)
Ejemplo n.º 5
0
def store_structure_node(path, wiki_text, author, argument=None):
    slot_path = path.rsplit('.', 1)[0]
    slot = get_node_for_path(slot_path)
    structure_schema = backend.parse(wiki_text, None)
    clone_candidates = None
    if argument:
        clone_candidates = slot.children.all()
    structure_node = backend.create_structure_from_structure_node_schema(
        structure_schema, slot, author, clone_candidates)
    # add auto follow
    create_vote(author, [structure_node])
    return structure_node, get_good_path_for_structure_node(structure_node,
                                                            slot, slot_path)
Ejemplo n.º 6
0
def store_derivate(path, arg_text, arg_type, derivate_wiki_text, author):
    node = get_node_for_path(path)
    arg_title, arg_text = backend.split_title_from_text(arg_text)

    slot_path = path.rsplit('.', 1)[0]
    slot = get_node_for_path(slot_path)
    structure_schema = backend.parse(derivate_wiki_text, None)

    score_tree = build_score_tree(node, structure_schema)

    new_node, path_couples = backend.create_derivate_from_structure_node_schema(
        structure_schema, slot, author,  node, score_tree, arg_type, arg_title,
        arg_text)

    new_path = get_good_path_for_structure_node(new_node, slot, slot_path)
    return new_path, path_couples