22from fasthtml .common import *
33
44def render (todo ):
5- show = AX (todo .title , f'/todos/{ todo .id } ' , 'current-todo' )
5+ show = AX (todo .task , f'/todos/{ todo .id } ' , 'current-todo' )
66 edit = AX ('edit' , f'/edit/{ todo .id } ' , 'current-todo' )
77 dt = ' (done)' if todo .done else ''
88 return Li (show , dt , ' | ' , edit , id = f'todo-{ todo .id } ' )
99
10- app ,rt ,todos ,Todo = fast_app ('data/todos.db' , render , id = int , title = str , done = bool , pk = 'id' )
10+ app ,rt ,todos ,Todo = fast_app ('data/todos.db' , render , id = int , task = str , done = bool , pk = 'id' )
1111
1212@rt ("/" )
1313def get ():
14- inp = Input (id = "new-title " , name = "title " , placeholder = "New Todo" )
14+ inp = Input (id = "new-task " , name = "task " , placeholder = "New Todo" )
1515 add = Form (Group (inp , Button ("Add" )), hx_post = "/" , target_id = 'todo-list' , hx_swap = "beforeend" )
1616 card = Card (Ul (* todos (), id = 'todo-list' ), header = add , footer = Div (id = 'current-todo' )),
1717 return Titled ('Todo list' , card )
1818
1919@rt ("/" )
2020def post (todo :Todo ):
21- return todos .insert (todo ), Input (id = "new-title " , name = "title " , placeholder = "New Todo" , hx_swap_oob = 'true' )
21+ return todos .insert (todo ), Input (id = "new-task " , name = "task " , placeholder = "New Todo" , hx_swap_oob = 'true' )
2222
2323@rt ("/edit/{id}" )
2424def get (id :int ):
25- res = Form (Group (Input (id = "title " ), Button ("Save" )),
25+ res = Form (Group (Input (id = "task " ), Button ("Save" )),
2626 Hidden (id = "id" ), CheckboxX (id = "done" , label = 'Done' ),
2727 hx_put = "/" , target_id = f'todo-{ id } ' , id = "edit" )
2828 return fill_form (res , todos [id ])
@@ -34,7 +34,7 @@ def put(todo: Todo): return todos.update(todo), clear('current-todo')
3434def get (id :int ):
3535 todo = todos [id ]
3636 btn = Button ('delete' , hx_delete = f'/todos/{ todo .id } ' , target_id = f'todo-{ id } ' , hx_swap = "outerHTML" )
37- return Div (Div (todo .title ), btn )
37+ return Div (Div (todo .task ), btn )
3838
3939@rt ("/todos/{id}" )
4040def delete (id :int ):
0 commit comments