def test_create_note(): conn = get_conn() note = Note.create(conn, note="This is a new note.", created_at = datetime.datetime.now()) assert note.id == 1 assert note.elapsed_seconds() < 0.01 project = Project.create( conn, name = "My Project With Notes", created_at = datetime.datetime.now() ) note2 = Note.create( conn, note="This is a note assigned to a project.", linked_to_type="Project", linked_to_id=project.id, created_at=datetime.datetime.now() ) assert note2.id == 2 inbox_notes = [n.id for n in Note.inbox(conn)] assert note.id in inbox_notes assert not note2.id in inbox_notes note.assign(conn, project) inbox_notes = [n.id for n in Note.inbox(conn)] assert not note.id in inbox_notes assert not note2.id in inbox_notes note = note.reload(conn) assert note.project(conn).id == project.id assert note2.project(conn).id == project.id
def delete_command( n=-1, p=-1, t=-1 # id of the note to delete # id of the project to delete # id of the task to delete ): """ Delete the note, project or task specified. """ c = conn() if n > 0: Note.delete(c, n) elif p > 0: Project.delete(c, p) elif t > 0: Task.delete(c, t) else: raise Exception()
def archive_command( n=-1, p=-1, t=-1 # id of the note to archive # id of the project to archive # id of the task to archive ): """ Archive the note, project or task specified. """ c = conn() if n > 0: Note.archive(c, n) elif p > 0: Project.archive(c, p) elif t > 0: Task.archive(c, t) else: raise Exception()
def update_command(t=-1, p=-1, n=-1, r=-1, **kwargs): """ Update a project, task or note with the supplied kwargs. """ c = conn() if t > 0: Task.update(c, t, kwargs) elif n > 0: Note.update(c, n, kwargs) elif p > 0: Project.update(c, p, kwargs) elif r > 0: Recipe.update(c, r, kwargs) else: raise Exception("Must specify one of t (task), n (note), p (project) or r (recipe).")
def assign_command(n=-1, p=-1, t=-1): """ Assign a note to a project or task, or a task to a project. """ c = conn() if n > 0: # We are assigning a note to a project or task. if p > 0: element = Project.get(c, p) elif t > 0: element = Task.get(c, t) else: raise Exception("You must specify either a project id or a task id.") note = Note.get(c, n) note.assign(c, element) elif t > 0: task = Task.get(c, t) # We are assigning a task to a project. if p > 0: project = Project.get(c, p) task.assign(c, project) else: raise Exception("You must specify a project id to assign the task to.") else: raise Exception("You didn't specify anything to assign!")
def note_command( note="", # the contents of the note p=-1, # the project id to link the new note to (optional) t=-1, # the task id to link the new note to (optional) ): """ Create a new note. If note contents are not specified, will read from STDIN. """ c = conn() if len(note) == 0: note = sys.stdin.read().strip() if len(note) == 0: raise Exception("You didn't pass any content for your note!") n = Note.create(c, note=note, created_at=datetime.now()) print "Created note", n.id if p > 0: project = Project.get(c, p) n.assign(c, project) print "Assigned to project %s" % p elif t > 0: task = Task.get(c, t) n.assign(c, task) print "Assigned to task %s" % t
def notes_command(): """ Lists all notes. """ notes = Note.all(conn()) for note in notes: print note.display_line() if len(notes) == 0: print "No notes found."
def inbox_command(): """ Lists all notes and tasks that are still in the 'inbox', i.e. not assigned to projects, tasks or other elements. """ c = conn() notes = Note.inbox(c) for note in notes: print note.display_line() tasks = Task.inbox(c) for task in tasks: print task.display_line()
def show_command( t=-1, # id of task to show detail on n=-1, # id of note to show detail on p=-1, # id of project to show detail on portfolio=-1, # id of portfolio to show detail on ): """ Print detailed information for a project, task, note or portfolio. """ c = conn() if t > 0: task = Task.get(c, t) print task.show() elif n > 0: note = Note.get(c, n) print note.show() elif p > 0: project = Project.get(c, p) print project.show() elif portfolio > 0: portfolio = Portfolio.get(c, portfolio) print portfolio.show() else: raise Exception("Must specify one of t (task), n (note), p (project) or portfolio.")
def inbox_notes(self): return Note.inbox(conn())