def testOnlyListTasks(self): prj = dbutils.getOrCreateProject("p1", interactive=False) t1 = dbutils.addTask("p1", "Task", {}) t2 = dbutils.addTask("p1", "Note", {NOTE_KEYWORD: None}) oldList = massedit.createEntriesForProject(prj) self.assertEqual(len(oldList), 1)
def testApplyMEditChangesUnknownIds(self): prj = dbutils.getOrCreateProject("p1", interactive=False) t1 = dbutils.addTask("p1", "Foo", {}) t2 = dbutils.addTask("p1", "Bar", {}) oldList = massedit.createEntriesForProject(prj) newList = [ MEditEntry(t1.id, "new", t1.title, {}), MEditEntry(t2.id + 1, "new", t2.title, {}), ] self.assertRaises(YokadiException, massedit.applyChanges, prj, oldList, newList, interactive=False)
def do_t_medit(self, line): """Mass edit tasks of a project. t_medit <project_name> Starts a text editor with the task list, you can then: - edit tasks text and keywords - mark tasks as done or started - add new tasks - adjust urgency - delete tasks """ if not line: raise BadUsageException("Missing parameters") projectName = parseutils.parseOneWordName(line) projectName = self._realProjectName(projectName) project = dbutils.getOrCreateProject(projectName) if not project: return oldList = massedit.createEntriesForProject(project) oldText = massedit.createMEditText(oldList) newText = oldText while True: newText = tui.editText(newText, suffix=".medit") if newText == oldText: print("No changes") return try: newList = massedit.parseMEditText(newText) except massedit.ParseError as exc: print(exc) print() if tui.confirm("Modify text and try again"): lst = newText.splitlines() lst.insert(exc.lineNumber, "# ^ " + exc.message) newText = "\n".join(lst) continue else: return try: massedit.applyChanges(project, oldList, newList) self.session.commit() break except YokadiException as exc: print(exc) print() if not tui.confirm("Modify text and try again"): return
def do_t_medit(self, line): """Mass edit tasks of a project. t_medit <project_name> Starts a text editor with the task list, you can then: - edit tasks text and keywords - mark tasks as done or started - add new tasks - adjust urgency - delete tasks """ if not line: raise BadUsageException("Missing parameters") projectName = parseOneWordName(line) projectName = self._realProjectName(projectName) project = dbutils.getOrCreateProject(projectName) if not project: return oldList = massedit.createEntriesForProject(project) oldText = massedit.createMEditText(oldList) newText = oldText while True: newText = tui.editText(newText, suffix=".medit") if newText == oldText: print("No changes") return try: newList = massedit.parseMEditText(newText) except massedit.ParseError as exc: print(exc) print() if tui.confirm("Modify text and try again"): lst = newText.splitlines() lst.insert(exc.lineNumber, "# ^ " + exc.message) newText = "\n".join(lst) continue else: return try: massedit.applyChanges(project, oldList, newList) self.session.commit() break except YokadiException as exc: print(exc) print() if not tui.confirm("Modify text and try again"): return
def testApplyMEditChanges(self): prj = dbutils.getOrCreateProject("p1", interactive=False) t1 = dbutils.addTask("p1", "Change text", {}) tui.addInputAnswers("y", "y") t2 = dbutils.addTask("p1", "Change keywords", {"k1": None, "k2": 1}) t3 = dbutils.addTask("p1", "Done", {}) t3.status = "started" self.session.merge(t3) t4 = dbutils.addTask("p1", "Deleted", {}) t5 = dbutils.addTask("p1", "Moved", {}) self.session.commit() deletedId = t4.id oldList = massedit.createEntriesForProject(prj) newList = [ MEditEntry(None, "new", u"Added", {}), MEditEntry(t1.id, "new", u"New text", {}), MEditEntry(t2.id, "new", u"Change keywords", { "k2": 2, "k3": None }), MEditEntry(t5.id, "new", u"Moved", {}), MEditEntry(t3.id, "done", u"Done", {}), ] massedit.applyChanges(prj, oldList, newList, interactive=False) self.session.commit() newTask = self.session.query(db.Task).filter_by(title=u"Added").one() self.assertEqual(t1.title, u"New text") self.assertEqual(t2.getKeywordDict(), {"k2": 2, "k3": None}) self.assertEqual(t3.status, "done") self.assertTrue(t3.doneDate) self.assertRaises(YokadiException, dbutils.getTaskFromId, deletedId) self.assertEqual(newTask.urgency, 5) self.assertEqual(t1.urgency, 4) self.assertEqual(t2.urgency, 3) self.assertEqual(t5.urgency, 2) self.assertEqual(t3.urgency, 1)
def testApplyMEditChanges(self): prj = dbutils.getOrCreateProject("p1", interactive=False) t1 = dbutils.addTask("p1", "Change text", {}) tui.addInputAnswers("y", "y") t2 = dbutils.addTask("p1", "Change keywords", {"k1": None, "k2": 1}) t3 = dbutils.addTask("p1", "Done", {}) t3.status = "started" self.session.merge(t3) t4 = dbutils.addTask("p1", "Deleted", {}) t5 = dbutils.addTask("p1", "Moved", {}) self.session.commit() deletedId = t4.id oldList = massedit.createEntriesForProject(prj) newList = [ MEditEntry(None, "new", u"Added", {}), MEditEntry(t1.id, "new", u"New text", {}), MEditEntry(t2.id, "new", u"Change keywords", {"k2": 2, "k3": None}), MEditEntry(t5.id, "new", u"Moved", {}), MEditEntry(t3.id, "done", u"Done", {}), ] massedit.applyChanges(prj, oldList, newList, interactive=False) self.session.commit() newTask = self.session.query(db.Task).filter_by(title=u"Added").one() self.assertEqual(t1.title, u"New text") self.assertEqual(t2.getKeywordDict(), {"k2": 2, "k3": None}) self.assertEqual(t3.status, "done") self.assertTrue(t3.doneDate) self.assertRaises(YokadiException, dbutils.getTaskFromId, deletedId) self.assertEqual(newTask.urgency, 5) self.assertEqual(t1.urgency, 4) self.assertEqual(t2.urgency, 3) self.assertEqual(t5.urgency, 2) self.assertEqual(t3.urgency, 1)