def insert_subtopic(self, subtopic, index): """Inserts the given subtopic into the list of subtopics. index: The index to insert the subtopic before. If this is None, then the subtopic will be appended to the list. """ if index is None: index = len(self.subtopics) if self.subtopics: if index < len(self.subtopics): subtopic.order_number = self.subtopics[index].order_number for later_subtopic in self.subtopics[index:]: later_subtopic.order_number += 1 sqlite.connection.execute( "UPDATE topic SET order_number = order_number + 1 WHERE parent = ? AND order_number >= ?", (self.id, subtopic.order_number)) else: subtopic.order_number = self.subtopics[-1].order_number + 1 #print self.subtopics, index self.subtopics.insert(index, subtopic) subtopic.parent = self sqlite.store_topic(subtopic) #print self.subtopics, index, subtopic.id self.add_subtopic_observers(subtopic) subtopic.apply_to_all_child_passages( singleton_verse_to_passage_entry_map.add_passage_entry)
def insert_subtopic(self, subtopic, index): """Inserts the given subtopic into the list of subtopics. index: The index to insert the subtopic before. If this is None, then the subtopic will be appended to the list. """ if index is None: index = len(self.subtopics) if self.subtopics: if index < len(self.subtopics): subtopic.order_number = self.subtopics[index].order_number for later_subtopic in self.subtopics[index:]: later_subtopic.order_number += 1 sqlite.connection.execute("UPDATE topic SET order_number = order_number + 1 WHERE parent = ? AND order_number >= ?", (self.id, subtopic.order_number)) else: subtopic.order_number = self.subtopics[-1].order_number + 1 #print self.subtopics, index self.subtopics.insert(index, subtopic) subtopic.parent = self sqlite.store_topic(subtopic) #print self.subtopics, index, subtopic.id self.add_subtopic_observers(subtopic) subtopic.apply_to_all_child_passages(singleton_verse_to_passage_entry_map.add_passage_entry)
def save_item(self, item): """Saves changes to the given item.""" if isinstance(item, BasePassageList): sqlite.store_topic(item) else: sqlite.save_or_update_item(item)