def addTask(projectName, title, keywordDict=None, interactive=True): """Adds a task based on title and keywordDict. @param projectName: name of project as a string @param title: task title as a string @param keywordDict: dictionary of keywords (name : value) @param interactive: Ask user before creating project (this is the default) @type interactive: Bool @returns : Task instance on success, None if cancelled.""" session = db.getSession() if keywordDict is None: keywordDict = {} # Create missing keywords if not createMissingKeywords(keywordDict.keys(), interactive=interactive): return None # Create missing project project = getOrCreateProject(projectName, interactive=interactive) if not project: return None # Create task task = Task(creationDate=datetime.now().replace(second=0, microsecond=0), project=project, title=title, description="", status="new") session.add(task) task.setKeywordDict(keywordDict) session.merge(task) return task
def addTask(projectName, title, keywordDict=None, interactive=True): """Adds a task based on title and keywordDict. @param projectName: name of project as a string @param title: task title as a string @param keywordDict: dictionary of keywords (name : value) @param interactive: Ask user before creating project (this is the default) @type interactive: Bool @returns : Task instance on success, None if cancelled.""" if keywordDict is None: keywordDict = {} # Create missing keywords if not createMissingKeywords(keywordDict.keys(), interactive=interactive): return None # Create missing project project = getOrCreateProject(projectName, interactive=interactive) if not project: return None # Create task try: task = Task(creationDate=datetime.now(), project=project, title=title, description="", status="new") task.setKeywordDict(keywordDict) except DuplicateEntryError: raise YokadiException("A task named %s already exists in this project. Please find another name" % title) return task
def applyChanges(project, oldList, newList, interactive=True): """ Modify a project so that its task list is newList @param project: the project name @param oldList: a list of Task instances @param newList: a list of MEditEntry @param interactive: whether to confirm creation of new keywords """ session = db.getSession() # Sanity check: all ids in newList should be in oldList oldIds = set([x.id for x in oldList]) newIds = set([x.id for x in newList if x.id is not None]) unknownIds = newIds.difference(oldIds) if unknownIds: idString = ", ".join([str(x) for x in unknownIds]) raise YokadiException("Unknown id(s): %s" % idString) # Check keywords for entry in newList: for name in entry.keywords: dbutils.getOrCreateKeyword(name, interactive=interactive) # Remove tasks whose lines have been deleted for id in oldIds.difference(newIds): task = dbutils.getTaskFromId(id) session.delete(task) # Update existing tasks, add new ones nbTasks = len(newList) for pos, newEntry in enumerate(newList): if newEntry.id: task = dbutils.getTaskFromId(newEntry.id) else: task = Task(creationDate=datetime.now().replace(second=0, microsecond=0), project=project) task.title = newEntry.title task.setKeywordDict(newEntry.keywords) task.setStatus(newEntry.status) task.urgency = nbTasks - pos if newEntry.id: session.merge(task) else: session.add(task)