Try TODO app
Browse files- favicon.ico +0 -0
- main.py +48 -5
- picovars.css +2 -0
- requirements.txt +3 -1
favicon.ico
ADDED
|
|
main.py
CHANGED
|
@@ -1,11 +1,54 @@
|
|
| 1 |
from fasthtml.common import *
|
| 2 |
-
from fasthtml_hf import setup_hf_backup
|
| 3 |
|
| 4 |
-
app,rt = fast_app(
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
def
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
serve()
|
|
|
|
| 1 |
from fasthtml.common import *
|
|
|
|
| 2 |
|
| 3 |
+
app,rt,todos,Todo = fast_app(
|
| 4 |
+
'data/todos.db',
|
| 5 |
+
hdrs=[Style(':root { --pico-font-size: 100%; }')],
|
| 6 |
+
id=int, title=str, done=bool, pk='id')
|
| 7 |
|
| 8 |
+
id_curr = 'current-todo'
|
| 9 |
+
def tid(id): return f'todo-{id}'
|
| 10 |
|
| 11 |
+
@patch
|
| 12 |
+
def __ft__(self:Todo):
|
| 13 |
+
show = AX(self.title, f'/todos/{self.id}', id_curr)
|
| 14 |
+
edit = AX('edit', f'/edit/{self.id}' , id_curr)
|
| 15 |
+
dt = ' ✅' if self.done else ''
|
| 16 |
+
return Li(show, dt, ' | ', edit, id=tid(self.id))
|
| 17 |
+
|
| 18 |
+
def mk_input(**kw): return Input(id="new-title", name="title", placeholder="New Todo", required=True, **kw)
|
| 19 |
+
|
| 20 |
+
@rt("/")
|
| 21 |
+
async def get():
|
| 22 |
+
add = Form(Group(mk_input(), Button("Add")),
|
| 23 |
+
hx_post="/", target_id='todo-list', hx_swap="beforeend")
|
| 24 |
+
card = Card(Ul(*todos(), id='todo-list'),
|
| 25 |
+
header=add, footer=Div(id=id_curr)),
|
| 26 |
+
title = 'Todo list'
|
| 27 |
+
return Title(title), Main(H1(title), card, cls='container')
|
| 28 |
+
|
| 29 |
+
@rt("/todos/{id}")
|
| 30 |
+
async def delete(id:int):
|
| 31 |
+
todos.delete(id)
|
| 32 |
+
return clear(id_curr)
|
| 33 |
+
|
| 34 |
+
@rt("/")
|
| 35 |
+
async def post(todo:Todo): return todos.insert(todo), mk_input(hx_swap_oob='true')
|
| 36 |
+
|
| 37 |
+
@rt("/edit/{id}")
|
| 38 |
+
async def get(id:int):
|
| 39 |
+
res = Form(Group(Input(id="title"), Button("Save")),
|
| 40 |
+
Hidden(id="id"), CheckboxX(id="done", label='Done'),
|
| 41 |
+
hx_put="/", target_id=tid(id), id="edit")
|
| 42 |
+
return fill_form(res, todos.get(id))
|
| 43 |
+
|
| 44 |
+
@rt("/")
|
| 45 |
+
async def put(todo: Todo): return todos.upsert(todo), clear(id_curr)
|
| 46 |
+
|
| 47 |
+
@rt("/todos/{id}")
|
| 48 |
+
async def get(id:int):
|
| 49 |
+
todo = todos.get(id)
|
| 50 |
+
btn = Button('delete', hx_delete=f'/todos/{todo.id}',
|
| 51 |
+
target_id=tid(todo.id), hx_swap="outerHTML")
|
| 52 |
+
return Div(Div(todo.title), btn)
|
| 53 |
|
| 54 |
serve()
|
picovars.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root { --pico-font-size: 100%; }
|
| 2 |
+
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
python-fasthtml
|
| 2 |
huggingface-hub
|
| 3 |
-
fasthtml-hf
|
|
|
|
|
|
|
|
|
| 1 |
python-fasthtml
|
| 2 |
huggingface-hub
|
| 3 |
+
fasthtml-hf
|
| 4 |
+
python-multipart
|
| 5 |
+
sqlite-utils
|