todoapp, we can build in our initial feature set to manage task items.
requirements.txtfile, and installing it to our virtualenv:
db.jsonfile on disk
dbobject we will use to integrate and access the TinyDB functionality in our application
todo/main.pyin order to define a default configuration for our database file called
config/todo.yml.example. Modify the file to include the following:
dbobject that can be used throughout our code. There are many ways we could do this, however here we are going to use a framework hook.
app.dbobject, however in order for it to take affect we need to register the function as a hook with the framework. Add the following
hooksmeta option to our Todo app in
todoagain you will see that our hook is executed (via the
Basecontroller, however to keep code clean and organized we want to create an new controller called
todo my-command) or do we want a separate nested namespace (ex:
todo items my-command). As our application is still small, we will opt to embed our controllers commands under the primary namespace (to keep our commands and examples shorter).
todo/controllers/items.pyas a placeholder for our sub-commands:
Itemscontroller and sub-commands, so lets add the actual code that will support each of these features:
state(pending/complete), and also the
timestampof when it was created/updated. Notice that we've added arguments to the sub-command function, and not the controller because the
item_textargument is only relevant to the
createaction, and not the application or controller namespace as a whole.
[ ](checkbox) that will be "checked" when the item's state is
timestampand modifying the text. Let's update our todo item: