API reference¶
The API for the tasks project.
This module provides classes and functions to interact with the tasks database programmatically.
cusy.tasks.api.Task class¶
- class cusy.tasks.api.Task(summary: str = None, owner: str = None, state: str = 'todo', id: int = None)[source]¶
Defines the tasks type with the attributes summary, owner and state.
- Parameters:
summary (str) – Summary of a task. Defaults to None.
owner (str) – The person working on a task. Defaults to None.
state (str) – The status of a task. Defaults to ‘todo’.
id (int) – The unique identifier for the task. Defaults to None.
cusy.tasks.api.TasksDB class¶
- class cusy.tasks.api.TasksDB(db_path)[source]¶
Database class to access the tasks_db file.
- Parameters:
db_path (str or pathlib.Path) – Path to the database file.
- add_task(task: Task)[source]¶
Add a task to the database.
- Parameters:
task (Task) – The Task instance to add to the database.
- Returns:
The task id of the newly added task.
- Return type:
int
- Raises:
MissingSummaryError – If the task has no summary.
- count()[source]¶
Return the number of tasks in the database.
- Returns:
The number of tasks in the database.
- Return type:
int
- delete_task(task_id: int)[source]¶
Remove a task from the database.
- Parameters:
task_id (int) – The ID of the task to delete.
- Raises:
InvalidTaskIdError – If no task with the given ID exists.
- finish(task_id: int)[source]¶
Set a task state to ‘done’.
- Parameters:
task_id (int) – The ID of the task to update.
- Raises:
InvalidTaskIdError – If no task with the given ID exists.
- get_task(task_id: int)[source]¶
Return a task for the corresponding id.
- Parameters:
task_id (int) – ID of the task to retrieve.
- Returns:
Task instance from the database.
- Return type:
- Raises:
InvalidTaskIdError – If no task with the given ID exists.
- list_tasks(owner=None, state=None)[source]¶
Return a list of tasks filtered by owner and/or state.
- Parameters:
owner (str, optional) – Filter tasks by this owner. Defaults to
None.
state (str, optional) – Filter tasks by this state. Defaults to
None.
- Returns:
List of Task instances matching the filters. If no filters are specified, returns all tasks.
- Return type:
list[Task]
- path()[source]¶
Return the path to the database.
- Returns:
Path to the database file.
- Return type:
str or pathlib.Path
- start(task_id: int)[source]¶
Set a task state to ‘in progress’.
- Parameters:
task_id (int) – The ID of the task to update.
- Raises:
InvalidTaskIdError – If no task with the given ID exists.
- update_task(task_id: int, task_mods: Task)[source]¶
Update a task with modifications.
- Parameters:
task_id (int) – The ID of the task to update.
task_mods (Task) – Task instance containing the modifications to
apply.
- Raises:
InvalidTaskIdError – If no task with the given ID exists.
Exceptions¶
- exception cusy.tasks.api.TasksError[source]¶
Base exception class for the tasks module.
Parent class for MissingSummaryError and InvalidTaskIdError exceptions.