Skip to content

Commit 7d0e613

Browse files
Merge pull request #770 from nick-leung/fix/rename-title-to-task
[PR] Avoid 'title' kwarg collision in examples and demo: rename column to 'task'
2 parents 2328e1d + f6f5073 commit 7d0e613

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

demo/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
def render(item:'Todo'):
44
id = f'todo-{item.id}'
55
dellink = AX('Delete', hx_delete=f'/todo/{item.id}', target_id=id, hx_swap='delete')
6-
return Li(item.title, dellink, id=id)
6+
return Li(item.task, dellink, id=id)
77

88
auth = user_pwd_auth(user='s3kret', skip=[r'/favicon\.ico', r'/static/.*', r'.*\.css'])
99
app,rt,todos,Todo = fast_app(
1010
'data/tbl.db', middleware=[auth], render=render,
11-
id=int, title=str, pk='id')
11+
id=int, task=str, pk='id')
1212

1313
@rt("/")
1414
async def get(request):
1515
new_frm = Form(hx_post='/', target_id='todo-list', hx_swap='beforeend')(
1616
Group(
17-
Input(name='title', placeholder='Title'),
17+
Input(name='task', placeholder='Task'),
1818
Button('Add')
1919
)
2020
)

examples/todos1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from fasthtml.common import *
22

3-
app,rt,todos,Todo = fast_app('data/todos.db', id=int, title=str, done=bool, pk='id')
3+
app,rt,todos,Todo = fast_app('data/todos.db', id=int, task=str, done=bool, pk='id')
44

55
def TodoRow(todo):
66
return Li(
7-
A(todo.title, href=f'/todos/{todo.id}'),
7+
A(todo.task, href=f'/todos/{todo.id}'),
88
(' (done)' if todo.done else '') + ' | ',
99
A('edit', href=f'/edit/{todo.id}'),
1010
id=f'todo-{todo.id}'
@@ -13,7 +13,7 @@ def TodoRow(todo):
1313
def home():
1414
add = Form(
1515
Group(
16-
Input(name="title", placeholder="New Todo"),
16+
Input(name="task", placeholder="New Todo"),
1717
Button("Add")
1818
), action="/", method='post'
1919
)
@@ -46,7 +46,7 @@ def get(id:int):
4646
def get(id:int):
4747
res = Form(
4848
Group(
49-
Input(id="title"),
49+
Input(id="task"),
5050
Button("Save")
5151
),
5252
Hidden(id="id"),
@@ -60,7 +60,7 @@ def get(id:int):
6060
@rt("/todos/{id}")
6161
def get(id:int):
6262
contents = Div(
63-
Div(todos[id].title),
63+
Div(todos[id].task),
6464
A('Delete', href=f'/remove?id={id}', role="button"),
6565
A('Back', href='/', role="button")
6666
)

examples/todos3.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
from fasthtml.common import *
33

44
def 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("/")
1313
def 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("/")
2020
def 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}")
2424
def 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')
3434
def 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}")
4040
def delete(id:int):

examples/todos4.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
db = database('data/todos.db')
44
todos = db.t.todos
5-
if todos not in db.t: todos.create(id=int, title=str, done=bool, pk='id')
5+
if todos not in db.t: todos.create(id=int, task=str, done=bool, pk='id')
66
Todo = todos.dataclass()
77

88
id_curr = 'current-todo'
@@ -18,12 +18,12 @@ def get(fname:str, ext:str): return FileResponse(f'{fname}.{ext}')
1818

1919
@patch
2020
def __ft__(self:Todo):
21-
show = AX(self.title, f'/todos/{self.id}', id_curr)
21+
show = AX(self.task, f'/todos/{self.id}', id_curr)
2222
edit = AX('edit', f'/edit/{self.id}' , id_curr)
2323
dt = ' (done)' if self.done else ''
2424
return Li(show, dt, ' | ', edit, id=tid(self.id))
2525

26-
def mk_input(**kw): return Input(id="new-title", name="title", placeholder="New Todo", **kw)
26+
def mk_input(**kw): return Input(id="new-task", name="task", placeholder="New Todo", **kw)
2727
def clr_details(): return Div(hx_swap_oob='innerHTML', id=id_curr)
2828

2929
@rt("/")
@@ -44,7 +44,7 @@ def post(todo:Todo): return todos.insert(todo), mk_input(hx_swap_oob='true')
4444

4545
@rt("/edit/{id}")
4646
def get(id:int):
47-
res = Form(Group(Input(id="title"), Button("Save")),
47+
res = Form(Group(Input(id="task"), Button("Save")),
4848
Hidden(id="id"), CheckboxX(id="done", label='Done'),
4949
hx_put="/", target_id=tid(id), id="edit")
5050
return fill_form(res, todos[id])
@@ -57,7 +57,7 @@ def get(id:int):
5757
todo = todos[id]
5858
btn = Button('delete', hx_delete=f'/todos/{todo.id}',
5959
target_id=tid(todo.id), hx_swap="outerHTML")
60-
return Div(Div(todo.title), btn)
60+
return Div(Div(todo.task), btn)
6161

6262
serve()
6363

0 commit comments

Comments
 (0)