def create_initial_data(): root = get_root_node() decided = create_user("Beschluss_Programm", description="Diese Vorschläge wurden in ihrer urspünglichen " "Fassung schon von einem Parteitag beschlossen. " "Weiterentwicklungen dieser Vorschläge sind " "natürlich kein beschlossenes Programm.", groups=['texters', 'voters', 'bloggers']) with open(project_path("initial_data/root.txt"), 'r') as f: lines = f.readlines() for l in lines: if comment_line_pattern.match(l): continue slot_name, src_file = l.split() assert re.match('^' + SHORT_TITLE + '$', slot_name), \ "Invalid short title '%s'." % slot_name src_path = project_path(os.path.join('initial_data', src_file)) assert os.path.exists(src_path), \ "Source file not found: '%s'." % src_path print("Creating '%s' from file '%s'." % (slot_name, src_path)) slot = create_slot(slot_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)
def setUp(self): max = create_user("Max") self.root = get_root_node() self.slot1 = create_slot("Slot_1") self.root.append_child(self.slot1) self.text1 = create_textNode("Irrelevant long title","My text.",[max]) self.slot1.append_child(self.text1) self.slot2 = create_slot("Slot_2") self.root.append_child(self.slot2) self.text3 = create_textNode("Irrelevant long title 2","My other text.",[max]) self.slot2.append_child(self.text3) self.text4 = create_textNode("Irrelevant long title 3","Yet another text.",[max]) self.slot2.append_child(self.text4) self.slot3 = create_slot("Slot_3") self.root.append_child(self.slot3) self.text5 = create_textNode("Irrelevant long title 4","Yet another text. Different in the second part.",[max]) self.slot3.append_child(self.text5) self.text6 = create_textNode("Irrelevant long title 5","Yet another text. Number 3.",[max]) self.slot3.append_child(self.text6) create_vote(max, [self.text5]) self.slot4 = create_slot("Slot_4") self.root.append_child(self.slot4) self.structure1 = create_structureNode("Structure1 Title","Introductory text",[max]) self.slot4.append_child(self.structure1) self.structure2 = create_structureNode("Structure2 Title","Introductory text 2",[max]) self.slot4.append_child(self.structure2) self.subslot1 = create_slot("SubSlot_1") self.structure1.append_child(self.subslot1) self.subslot2 = create_slot("SubSlot_2") self.structure2.append_child(self.subslot2) self.substructure1 = create_structureNode("SubStructure2 Title","Introductory text 3",[max]) self.subslot1.append_child(self.substructure1) self.subslot2.append_child(self.substructure1) self.subsubslot1 = create_slot("SubSubSlot_1") self.substructure1.append_child(self.subsubslot1) self.subsubtext1 = create_textNode("SubSubText1 Title","Yet another text. Number 4.",[max]) self.subsubslot1.append_child(self.subsubtext1) self.argument1 = create_argument(type='pro',text="It is good!",authors=[max]) self.subsubtext1.append_argument(self.argument1) self.argument2 = create_argument(type='neut',text="Maybe consider something",authors=[max]) self.subsubtext1.append_argument(self.argument2)
def test_post_node_was_flagged_message(self): hugo = create_user('Hugo') post = post_node_was_flagged_message('/', hugo) self.assertEqual(post.author, get_system_user()) self.assertEqual(post.location, get_root_node()) self.assertEqual(post.post_type, Post.SPAM_MARKED) self.assertIn(hugo, post.mentions.all()) self.assertEqual( post.text_cache, '<span style="color: gray;">Hinweis:</span> ' + '<a href="/user/Hugo">@Hugo</a> hat <a href="/">ROOT' '<span class="nodeIndex">1</span></a> als Spam markiert.')
def test_post_node_was_flagged_message(self): hugo = create_user('Hugo') post = post_node_was_flagged_message('/', hugo) self.assertEqual(post.author, get_system_user()) self.assertEqual(post.location, get_root_node()) self.assertEqual(post.post_type, Post.SPAM_MARKED) self.assertIn(hugo, post.mentions.all()) self.assertEqual( post.text_cache, '<span style="color: gray;">Hinweis:</span> ' + '<a href="/user/Hugo">@Hugo</a> hat <a href="/">ROOT' '<span class="nodeIndex">1</span></a> als Spam markiert.')
def forwards(self, orm): for post in orm['microblogging.Post'].objects.all(): text = self.replace_node_references(post.text) text = strip_tags(text) schema = parse_microblogging(text, post.author, '/', get_root_node()) post.text_template = schema['template_text'] post.location_id, post.node_references =\ self.get_location_and_references(list(post.node_references.all()), schema['references']) if post.node_references.count() < len(schema['references']): print("Missing reference! Adding location to node references.") post.node_references.add(post.location) if post.node_references.count() < len(schema['references']): print("Missing reference! Using references from the Text.") post.node_references = [orm['node_storage.Node'].objects.get(id=r.id) for r in schema['references']] self.post_render(post) post.save()
def forwards(self, orm): for post in orm["microblogging.Post"].objects.all(): text = self.replace_node_references(post.text) text = strip_tags(text) schema = parse_microblogging(text, post.author, "/", get_root_node()) post.text_template = schema["template_text"] post.location_id, post.node_references = self.get_location_and_references( list(post.node_references.all()), schema["references"] ) if post.node_references.count() < len(schema["references"]): print("Missing reference! Adding location to node references.") post.node_references.add(post.location) if post.node_references.count() < len(schema["references"]): print("Missing reference! Using references from the Text.") post.node_references = [orm["node_storage.Node"].objects.get(id=r.id) for r in schema["references"]] self.post_render(post) post.save()
def get_location_and_references(self, candidates, references): """ Findes the one reference which is not mentioned in the text. If all are mentioned in the text it returns the first one. :rtype : (node, [node]) """ try: location_id = candidates[0].id except IndexError: if len(references) > 0: location_id = references[0].id else: location_id = get_root_node().id new_references = [] for candidate in candidates: if not candidate.id in [x.id for x in references]: location_id = candidate.id else: new_references.append(candidate) return location_id, new_references
def get_location_and_references(self, candidates, references): """ Findes the one reference which is not mentioned in the text. If all are mentioned in the text it returns the first one. :rtype : (node, [node]) """ try: location_id = candidates[0].id except IndexError: if len(references) > 0: location_id = references[0].id else: location_id = get_root_node().id new_references = [] for candidate in candidates: if not candidate.id in [x.id for x in references]: location_id = candidate.id else: new_references.append(candidate) return location_id, new_references
def setUp(self): self.horst = create_user('horst') self.udo = create_user('udo') self.root = get_root_node() self.slot1 = create_slot('soon_empty') self.root.append_child(self.slot1) self.node = create_structureNode('To be or not to be', 'never both') self.slot1.append_child(self.node) self.arg = create_argument(self.node, 'c', "no", "lyrics") self.path = 'soon_empty.1' self.child_slot = create_slot('or_to_pee') self.node.append_child(self.child_slot) self.child = create_structureNode('or to pee') self.child_slot.append_child(self.child) TextCache.objects.create(path=self.path, paragraphs="doesn't matter") IndexCache.objects.create(path=self.path, index_nodes="doesn't matter") self.slot2 = create_slot('verfassungswiedrig') self.root.append_child(self.slot2) self.source = create_structureNode('BöserTitel', 'gewöhnlicher text') self.slot2.append_child(self.source) self.derivate = create_structureNode('BöserTitel', 'verfassungswiedriger text') self.slot2.append_child(self.derivate) self.source.add_derivate(self.derivate, arg_type='con', title="zuSchwach", text="muss fieser werden", authors=[self.udo]) self.source_path = 'verfassungswiedrig.1' self.derivate_path = 'verfassungswiedrig.2' create_vote(self.udo, [self.node]) create_vote(self.horst, [self.source, self.node]) create_spam_flag(self.horst, [self.node]) create_post('i reference /verfassungswiedrig.1 because i like it ', self.horst, self.path)
def setUp(self): self.root = get_root_node()
def setUp(self): self.hugo = create_user('hugo') self.herbert = create_user('herbert') self.root = get_root_node() self.foo1 = create_nodes_for_path('foo.1') self.foo2 = create_nodes_for_path('foo.2')
def create_initial_data(): root = get_root_node() decided = create_user("Beschlossenes Programm") # create_some_microblogging() # Grundsatzprogramm Bundesweit # grundsatzprogramm = create_slot("Grundsatzprogramm") # root.append_child(grundsatzprogramm) # with open("initial_data/grundsatzprogramm_bund.txt", 'r') as f: # gsp_text = f.read() # schema = parse(unicode(gsp_text, encoding='utf-8'), grundsatzprogramm.title) # create_structure_from_structure_node_schema(schema, grundsatzprogramm, [decided]) # create_some_microblogging("Grundsatzprogramm.1") # Wahlprogramm BTW # wahlprogramm_btw = create_slot("Wahlprogramm_BTW") # root.append_child(wahlprogramm_btw) # with open("initial_data/wahlprogramm_btw.txt", 'r') as f: # wpbtw_text = f.read() # schema = parse(unicode(wpbtw_text, encoding='utf-8'), wahlprogramm_btw.title) # create_structure_from_structure_node_schema(schema, wahlprogramm_btw, [decided]) # create_alternatives_for_urheberrecht("Wahlprogramm_BTW.1/Urheberrecht.1") # create_some_microblogging("Wahlprogramm_BTW.1/Urheberrecht.1") # Positionspapiere Bund # posp_bund = create_slot("Positionspapiere") # root.append_child(posp_bund) # with open("initial_data/positionspapiere_bund.txt", 'r') as f: # pospbund_text = f.read() # schema = parse(unicode(pospbund_text, encoding='utf-8'), posp_bund.title) # create_structure_from_structure_node_schema(schema, posp_bund, [decided]) # Wahlprogramm Rheinland-Pfalz wahlprogramm_rlp = create_slot("Wahlprogramm_RLP") root.append_child(wahlprogramm_rlp) with open("initial_data/wahlprogramm_rlp.txt", "r") as f: wahlprogrammrlp_text = f.read() schema = parse(unicode(wahlprogrammrlp_text, encoding="utf-8"), wahlprogramm_rlp.title) create_structure_from_structure_node_schema(schema, wahlprogramm_rlp, [decided]) # Positionspapiere Rheinland-Pfalz posp_rlp = create_slot("Positionspapiere_RLP") root.append_child(posp_rlp) with open("initial_data/positionspapiere_rlp.txt", "r") as f: posprlp_text = f.read() schema = parse(unicode(posprlp_text, encoding="utf-8"), posp_rlp.title) create_structure_from_structure_node_schema(schema, posp_rlp, [decided]) # Satzung Rheinland-Pfalz satzung_rlp = create_slot("Satzung_RLP") root.append_child(satzung_rlp) with open("initial_data/satzung_rlp.txt", "r") as f: satzungrlp_text = f.read() schema = parse(unicode(satzungrlp_text, encoding="utf-8"), satzung_rlp.title) create_structure_from_structure_node_schema(schema, satzung_rlp, [decided]) # Spielwiese spielwiese = create_slot("Spielwiese") root.append_child(spielwiese) with open("initial_data/spielwiese.txt", "r") as f: spielwiese_text = f.read() schema = parse(unicode(spielwiese_text, encoding="utf-8"), spielwiese.title) create_structure_from_structure_node_schema(schema, spielwiese, [decided])
def setUp(self): self.hugo = create_user('hugo') self.herbert = create_user('herbert') self.root = get_root_node() self.foo1 = create_nodes_for_path('foo.1') self.foo2 = create_nodes_for_path('foo.2')
def setUp(self): max = create_user("Max") self.root = get_root_node() self.slot1 = create_slot("Slot_1") self.root.append_child(self.slot1) self.text1 = create_textNode("Irrelevant long title", "My text.", [max]) self.slot1.append_child(self.text1) self.slot2 = create_slot("Slot_2") self.root.append_child(self.slot2) self.text3 = create_textNode("Irrelevant long title 2", "My other text.", [max]) self.slot2.append_child(self.text3) self.text4 = create_textNode("Irrelevant long title 3", "Yet another text.", [max]) self.slot2.append_child(self.text4) self.slot3 = create_slot("Slot_3") self.root.append_child(self.slot3) self.text5 = create_textNode( "Irrelevant long title 4", "Yet another text. Different in the second part.", [max]) self.slot3.append_child(self.text5) self.text6 = create_textNode("Irrelevant long title 5", "Yet another text. Number 3.", [max]) self.slot3.append_child(self.text6) create_vote(max, [self.text5]) self.slot4 = create_slot("Slot_4") self.root.append_child(self.slot4) self.structure1 = create_structureNode("Structure1 Title", "Introductory text", [max]) self.slot4.append_child(self.structure1) self.structure2 = create_structureNode("Structure2 Title", "Introductory text 2", [max]) self.slot4.append_child(self.structure2) self.subslot1 = create_slot("SubSlot_1") self.structure1.append_child(self.subslot1) self.subslot2 = create_slot("SubSlot_2") self.structure2.append_child(self.subslot2) self.substructure1 = create_structureNode("SubStructure2 Title", "Introductory text 3", [max]) self.subslot1.append_child(self.substructure1) self.subslot2.append_child(self.substructure1) self.subsubslot1 = create_slot("SubSubSlot_1") self.substructure1.append_child(self.subsubslot1) self.subsubtext1 = create_textNode("SubSubText1 Title", "Yet another text. Number 4.", [max]) self.subsubslot1.append_child(self.subsubtext1) self.argument1 = create_argument(self.subsubtext1, arg_type='pro', text="It is good!", authors=[max]) self.argument2 = create_argument(self.subsubtext1, arg_type='neut', text="Maybe consider something", authors=[max])