Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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