Пример #1
0
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!")
Пример #2
0
def project_command(
    name=None,  # the name of the project (required)
    description="",  # an optional description for this project
    p=-1,  # portfolio id for this project (required unless parent project specified)
    parent=-1,  # parent project id, if this is a subproject
):
    """
    Create a new project.
    """
    c = conn()

    if parent > 0:
        parent_project_id = parent
        parent_project = Project.get(c, parent)
        portfolio_id = parent_project.portfolio_id
    else:
        parent_project_id = None
        if p > 0:
            portfolio_id = p
        else:
            raise Exception(
                "You must provide a portfolo id using the -p parameter if this project doesn't have a parent project."
            )

    project = Project.create(
        c,
        created_at=datetime.now(),
        description=description,
        parent_project_id=parent_project_id,
        name=name,
        portfolio_id=portfolio_id,
    )
    print project.id,
Пример #3
0
def test_create_table():
    conn = Model.setup_db()
    Project.create_table(conn)
    sql = "select * from sqlite_master where type='table' and name='Project'"
    assert len(conn.execute(sql).fetchall()) == 1
    row = conn.execute(sql).fetchone()
    assert row['sql'] == Project.create_table_sql()
    conn.execute("select * from Project")
Пример #4
0
def test_create_project():
    conn = get_conn()
    project = Project.create(conn, name="My New Project", created_at = datetime.datetime.now())
    assert project.id == 1
    assert project.elapsed_seconds() < 0.01

    lookup_project = Project.get(conn, 1)
    assert lookup_project.name == "My New Project"
    assert project.elapsed_seconds() < 0.01
Пример #5
0
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()
Пример #6
0
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()
Пример #7
0
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).")
Пример #8
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
Пример #9
0
def complete_command(p=-1, t=-1):  # id of the project to mark complete  # id of the task to mark complete
    """
    Mark the project or task as completed.
    """
    c = conn()
    if p > 0:
        project = Project.get(c, p)
        project.complete(c)
        Project.archive(c, project.id)
        print "Project %s marked as complete!" % p
    elif t > 0:
        task = Task.get(c, t)
        task.complete(c)
        print "Task %s marked as complete!" % t
    else:
        raise Exception()
Пример #10
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
Пример #11
0
def projects_command():
    """
    List all projects.
    """
    c = conn()
    projects = Project.all_nested_subprojects(c)
    for project in projects:
        print project.display_line()
    if len(projects) == 0:
        print "No projects found. Run 'ado help' if you need help."
Пример #12
0
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.")
Пример #13
0
 def projects(self, conn=None):
     if not conn:
         conn = self.conn
     sql = "select * from %s where portfolio_id = ? and archived_at IS NULL" % Project.table_name()
     return [Project.load(conn, row) for row in conn.execute(sql, [self.id])]
Пример #14
0
 def projects(self):
     return Project.all_nested_subprojects(conn())
Пример #15
0
def test_table_name():
    assert Model.table_name() == "Model"
    assert Project.table_name() == "Project"
Пример #16
0
def test_persist_instance():
    conn = Model.setup_db()
    Project.create_table(conn)
    project = Project.create(conn, name="My New Project")
    print project.persist_instance_sql()
    print project.persist(conn)