-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (59 loc) · 2.06 KB
/
app.py
File metadata and controls
73 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
import json
import asyncio
from pyodide.http import pyfetch
from pyodide import JsException,create_proxy
import js
async def GetTasks():
response = await pyfetch(
url="http://127.0.0.1:8000/",
method="GET",
headers={"Content-Type": "application/json"},
)
if response.ok:
data = await response.json()
parent = js.document.querySelector("#todo-row")
js.document.querySelector('#taskadd').value =""
before_child = js.document.querySelectorAll(".task-test")
before_child2 = js.document.querySelectorAll("#del")
if before_child and before_child2:
for b in before_child:
b.remove()
for c in before_child2:
c.remove()
i=0
for t in data:
i +=1
html_data =js.document.createElement("h6")
html_data.className = "task-test col-8"
html_data.innerHTML = t["task"]
parent.appendChild(html_data)
button=js.document.createElement("button")
button.className = "btn btn-delete btn-outline-light btn-danger col-4"
button.innerHTML = "Delete"
button.value = t["id"]
button.setAttribute("id", "del")
button.addEventListener("click", create_proxy(delete))
parent.appendChild(button)
async def create(e):
task = js.document.querySelector('#taskadd').value
response = await pyfetch(
url=f"http://127.0.0.1:8000/",
method="POST",
headers={"Content-Type": "application/json"},
body = json.dumps({
"task":task
})
)
loop = asyncio.get_event_loop()
loop.run_until_complete(GetTasks())
async def delete(e):
id = e.target.value
response = await pyfetch(
url=f"http://127.0.0.1:8000/delete/{id}",
method="DELETE",
headers={"Content-Type": "application/json"},
)
loop = asyncio.get_event_loop()
loop.run_until_complete(GetTasks())
loop = asyncio.get_event_loop()
loop.run_until_complete(GetTasks())