-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyscript-demo.html
65 lines (58 loc) · 2.45 KB
/
pyscript-demo.html
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
<html>
<header>
<!-- script pyton -->
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</header>
<body>
<py-script>
from js import console
from datetime import datetime
tasks=[]
def atualiza_tasks():
tasks_criadas = Element('tasks_criadas')
tasks_criadas.element.innerText = ""
for i in tasks:
tasks_criadas.element.innerText += f"{i['content']}\n"
def cria_task(*ags, **kags):
input_task = Element('input_task')
task = input_task.element.value
y = list(filter(lambda x: x['content'] == task, tasks))
if len(y) > 0:
message = Element('message')
message.element.style.display = 'flex'
return None
dict_task = {'task-id': len(task),
'content': task,
'data': datetime.now(),
'status': 'C'}
tasks.append(dict_task)
input_task.element.value = ""
atualiza_tasks()
def add_task_event(e):
if e.key == "Enter":
cria_task()
input_task = Element('input_task')
input_task.element.onkeypress = add_task_event
</py-script>
<main>
<div class="container">
<br>
<div style="display: none" id="message" class="alert alert-danger" role="alert">
Essa tarefa já existe
</div>
<h3>Lista de Tarefas</h3>
<input id="input_task" type="text" placeholder="Digite uma tarefa" class="form-control">
<br>
<button id="btn_task" type="submit" class="btn brn-success" pys-onClick="cria_task">Enviar</button>
<hr>
<div class="row">
<h3 style="color: orange">Criadas</h3>
<div id="tasks_criadas">
<h3 style="color: green">Concluídas</h3>
</div>
</div>
</div>
</body>
</header>
</html>