-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
59 lines (44 loc) · 1.82 KB
/
test.py
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
#!/usr/bin/env python3
from typing import List
import pandas as pd
import models
from tortoise import Tortoise
from nicegui import app, ui
async def init_db() -> None:
await Tortoise.init(db_url='sqlite://stock_trading_records.db', modules={'models': ['models']})
await Tortoise.generate_schemas()
async def close_db() -> None:
await Tortoise.close_connections()
app.on_startup(init_db)
app.on_shutdown(close_db)
@ui.refreshable
async def list_of_users() -> None:
async def delete(record: models.stock_trading_record) -> None:
await record.delete()
list_of_users.refresh()
records:List[models.stock_trading_record]= await models.stock_trading_record.all()
for record in reversed(records):
# print(record)
with ui.card():
with ui.row().classes('items-center'):
ui.input('Code', on_change=record.save) \
.bind_value(record, 'code').on('blur', list_of_users.refresh)
ui.number('Price', on_change=record.save, format='%.0f') \
.bind_value(record, 'price').on('blur', list_of_users.refresh).classes('w-20')
ui.button(icon='delete',
on_click=lambda u=record: delete(u)).props('flat')
@ui.page('/')
async def index():
async def create() -> None:
await models.stock_trading_record.create(name=name.value, age=age.value or 0)
name.value = ''
age.value = None
list_of_users.refresh()
with ui.column().classes('mx-auto'):
with ui.row().classes('w-full items-center px-4'):
name = ui.input(label='Name')
age = ui.number(label='Age', format='%.0f').classes('w-20')
ui.button(on_click=create, icon='add').props(
'flat').classes('ml-auto')
await list_of_users()
ui.run()