def create_structure_from_structure_node_schema(schema, parent_slot, author, clone_candidates=None): if not clone_candidates: clone_candidates = [] clone_found = False for candidate in clone_candidates: if candidate.title == schema['title'] and \ candidate.text.text == schema['text'] and \ [child['short_title'] for child in schema['children']] == \ [child.title for child in candidate.children.all()]: structure = candidate clone_found = True if not clone_found: structure = create_structureNode(long_title=schema['title'], text=schema['text'], authors=[author]) parent_slot.append_child(structure) # auto-follows create_vote(author, [structure]) for child in schema['children']: if clone_found: child_slot = structure.children.get(title=child['short_title']) else: child_slot = create_slot(child['short_title']) structure.append_child(child_slot) sub_clone_candidate_group = [] for candidate in clone_candidates: for candidate_slot in candidate.children.filter( title=child['short_title']).all(): sub_clone_candidate_group += candidate_slot.children.all() create_structure_from_structure_node_schema(child, child_slot, author, sub_clone_candidate_group) return structure
def create_derivate_from_structure_node_schema(schema, parent_slot, author, origin, score_tree, arg_type=None, arg_title="", arg_text=""): new_path_couples = [] clone_found = False if origin.title == schema['title'] and \ origin.text.text == schema['text'] and \ [child['short_title'] for child in schema['children']] == \ [child.title for child in origin.children.all()]: structure = origin clone_found = True if not clone_found: structure = create_structureNode(long_title=schema['title'], text=schema['text'], authors=[author]) # auto-follow node create_vote(author, [structure]) # append node parent_slot.append_child(structure) arg = origin.add_derivate(structure, arg_type=arg_type, title=arg_title, text=arg_text, authors=[author]) # auto-follow argument #create_vote(author, [arg]) # data for microblogging message new_path_couples.append( (get_good_path_for_structure_node(origin, parent_slot), get_good_path_for_structure_node(structure, parent_slot))) for child in schema['children']: if clone_found: child_slot = structure.children.get(title=child['short_title']) else: if child['short_title'] in score_tree['slots']: child_slot = origin.children.get(title=child['short_title']) else: child_slot = create_slot(child['short_title']) structure.append_child(child_slot) best = 0, None # score, id if child['short_title'] in score_tree['slots']: for candidate in score_tree['slots'][child['short_title']]: if candidate['score'] >= best[0]: best = candidate['score'], candidate if best[0] > 0: sub_origin = Node.objects.get(id=best[1]['id']) _, sub_path_couples = create_derivate_from_structure_node_schema( child, child_slot, author, sub_origin, best[1], arg_type, arg_title, arg_text) new_path_couples += sub_path_couples else: create_structure_from_structure_node_schema(child, child_slot, author, []) return structure, new_path_couples