-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_test_script.py
85 lines (69 loc) · 1.81 KB
/
template_test_script.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from lona.html import HTML, H1, H2
from lona import LonaApp, LonaView
from lona_bootstrap_5 import (
TEMPLATE_DIR,
PrimaryButton,
MenuItem,
show_alert,
Select,
TextInput,
NumberInput,
)
app = LonaApp(__file__)
app.settings.TEMPLATE_DIRS = [
TEMPLATE_DIR,
]
app.settings.FRONTEND_TEMPLATE = 'bootstrap_5/sidebar_left.html'
app.settings.BOOTSTRAP_5_TITLE = 'My Fancy Script'
app.settings.BOOTSTRAP_5_VERSION_STRING = 'v0.1'
app.settings.BOOTSTRAP_5_DARK_NAVIGATION = True
app.settings.BOOTSTRAP_5_MENU = [
MenuItem(
title='Home',
url='/',
),
MenuItem(
title='Foo',
route_name='print',
route_args={'word': 'foo'},
),
MenuItem(
title='Bar',
route_name='print',
route_args={'word': 'bar'},
),
]
@app.route('/')
class IndexView(LonaView):
def handle_request(self, request):
alert_type = Select(
values=[
('info', 'Info'),
('success', 'Success'),
('warning', 'Warning'),
('danger', 'Danger'),
],
)
alert_text = TextInput(value='Test Alert')
alert_timeout = NumberInput(value=3000)
html = HTML(
H1('Lona Bootstrap 5'),
H2('Show Alert'),
alert_type,
alert_timeout,
alert_text,
PrimaryButton('Send'),
)
while True:
self.await_click(html=html)
show_alert(
lona_view=self,
type=alert_type.value,
text=alert_text.value,
timeout=alert_timeout.value,
)
@app.route('/print/<word>', name='print')
class PrintView(LonaView):
def handle_request(self, request):
return request.match_info['word']
app.run()