Reference
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
todo
project code.
To-Do entry point script.
main()
Run the todo CLI app.
Source code in src/todo/__main__.py
6 7 8 |
|
CLI for the Python To-Do app.
add(description=typer.Argument(...), priority=typer.Option(2, '--priority', '-p', min=1, max=3))
Add a new todo.
Source code in src/todo/cli.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
get_todoer()
Get the todo controller.
Source code in src/todo/cli.py
40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
init(db_path=typer.Option(str(database.DEFAULT_DB_FILE_PATH), '--db-path', '-db', prompt='to-do databae location?'))
Initialise the to-do database.
Source code in src/todo/cli.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
list_all()
List all to-do's.
Source code in src/todo/cli.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
main(version=typer.Option(None, '--version', '-v', help="Show the application's version and exit.", callback=_version_callback, is_eager=True))
CLI arguments for the main todo command.
Source code in src/todo/cli.py
183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
remove(todo_id=typer.Argument(...), *, force=typer.Option(False, '--force', '-f', help='Force deletion without confirmation.'))
Remove a todo using its ID.
Source code in src/todo/cli.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
remove_all(*, force=typer.Option(..., prompt='Delete all todos?', help='Force deletion without confirmation.'))
Remove all todo's.
Source code in src/todo/cli.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
set_done(todo_id=typer.Argument(...))
Mark a todo item as completed.
Source code in src/todo/cli.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
To-do app config functionality.
init_app(db_path)
Initialise the application.
Source code in src/todo/config.py
14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Functionality for the to-do app database.
DBResponse
Bases: NamedTuple
The database response containing the list of todo's and an error code.
:param todo_list: the list of todo's
:param error: a numeric error code, to be mapped to todo.ERRORS
Source code in src/todo/database.py
30 31 32 33 34 35 36 37 38 39 |
|
DatabaseHandler
Handle interactions with the to-do database.
Source code in src/todo/database.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
__init__(db_path)
Initialise the database handler for a given database.
:param db_path: the file path to the todo database. :type db_path: pathlib.Path
Source code in src/todo/database.py
45 46 47 48 49 50 51 52 53 |
|
read_todos()
Read the JSON todo database and return a DBResponse
instance.
Source code in src/todo/database.py
55 56 57 58 59 60 61 62 63 64 |
|
write_todos(todo_list)
Write to the JSON todo database and return a DBResponse
isntance.
Source code in src/todo/database.py
66 67 68 69 70 71 72 73 |
|
get_database_path(config_file)
Return the current path to the to-do database.
Source code in src/todo/database.py
13 14 15 16 17 |
|
init_database(db_path)
Create the to-do database.
Source code in src/todo/database.py
20 21 22 23 24 25 26 27 |
|
The todo model-controller.
CurrentTodo
Bases: NamedTuple
The data model for a given todo.
Contains the todo's information in a dictionary and an error code, signaling the status of any operation performed on the todo.
Source code in src/todo/todo.py
10 11 12 13 14 15 16 17 18 19 |
|
Todoer
The main Controller class, handling database connections.
Source code in src/todo/todo.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
__init__(db_path)
Initialise the Todoer class, composing it with an instance of DatabaseHandler.
Source code in src/todo/todo.py
25 26 27 |
|
add(description, priority=2)
Add a new todo to the database.
Source code in src/todo/todo.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
get_todo_list()
Get the current list of todo's.
Source code in src/todo/todo.py
49 50 51 52 |
|
remove(todo_id)
Remove a todo from the database.
Source code in src/todo/todo.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
remove_all()
Remove all todo's from the database.
Source code in src/todo/todo.py
85 86 87 88 |
|
set_done(todo_id)
Set a todo as done.
Source code in src/todo/todo.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|