-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmre.py
36 lines (29 loc) · 845 Bytes
/
mre.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
from fasthtml.common import *
app, rt = fast_app()
chapters = ['ch1', 'ch2', 'ch3']
lessons = {
'ch1': ['lesson1', 'lesson2', 'lesson3'],
'ch2': ['lesson4', 'lesson5', 'lesson6'],
}
def mk_opts(nm, cs):
return (
Option(f'-- select {nm} --', disabled='', selected='', value=''),
*map(Option, cs))
@app.get('/get_lesson')
def get_lesson_bug(chapter: str):
return Select(*mk_opts('lesson', lessons[chapter]), name='lesson')
@app.get('/')
def homepage():
chapter_dropdown = Select(
*mk_opts('chapter', chapters),
name='chapter',
get='get_lesson', hx_target='#lesson')
return Div(
Div(
Label("Chapter:", for_="chapter"),
chapter_dropdown),
Div(
Label("Lesson:", for_="lesson"),
Div(Div(id='lesson')),
))
serve()