Feat: 2nd page to create exam

This commit is contained in:
Bertrand Benjamin 2021-01-21 13:53:16 +01:00
parent eb1abbe868
commit 95fc842c1d
2 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,164 @@
#!/usr/bin/env python
# encoding: utf-8
import dash
import dash_html_components as html
import dash_core_components as dcc
from datetime import date
import uuid
from ...scripts.getconfig import config, CONFIGPATH
from ..app import app
def get_current_year_limit():
today = date.today()
if today.month > 8:
return {
"min_date_allowed": date(today.year, 9, 1),
"max_date_allowed": date(today.year + 1, 7, 15),
"initial_visible_month": today,
}
return {
"min_date_allowed": date(today.year - 1, 9, 1),
"max_date_allowed": date(today.year, 7, 15),
"initial_visible_month": today,
}
layout = html.Div(
[
html.Header(
children=[
html.H1("Création d'une évaluation"),
html.P("Dernière sauvegarde", id="lastsave"),
],
),
html.Main(
children=[
html.Form(
id="new-exam",
children=[
html.Label(
children=[
"Classe",
dcc.Dropdown(
id="tribe",
options=[
{"label": t["name"], "value": t["name"]}
for t in config["tribes"]
],
value=config["tribes"][0]["name"],
),
]
),
html.Label(
children=[
"Nom de l'évaluation",
dcc.Input(
id="name",
type="text",
placeholder="Nom de l'évaluation",
),
]
),
html.Label(
children=[
"Date",
dcc.DatePickerSingle(
id="my-date-picker-single",
date=date.today(),
**get_current_year_limit(),
),
]
),
html.Label(
children=[
"Trimestre",
dcc.Dropdown(
id="term",
options=[
{"label": i + 1, "value": i + 1}
for i in range(3)
],
value=1,
),
]
),
],
),
html.Div(
id="exercises",
children=[],
),
html.Button(
"Ajouter un exercice",
id="add-exercise",
className="add-exercise",
),
html.Div(
id="output",
),
]
),
dcc.Store(id="exam_store"),
]
)
@app.callback(
dash.dependencies.Output("exercises", "children"),
dash.dependencies.Input("add-exercise", "n_clicks"),
dash.dependencies.State("exercises", "children"),
)
def display_dropdowns(n_clicks, children):
new_element = html.Div(
children=[
html.Div(
children=[
dcc.Input(
id={"type": "exercice", "index": str("n_clicks")},
type="text",
placeholder="Nom de l'exercice",
className="exercise-name",
),
html.Button(
"X",
id=f"delete-exercise-{n_clicks}",
className="delete-exercise",
),
],
className="exercise-head",
),
html.Div(
id={"type": "elements", "index": str(n_clicks)},
children=[],
),
html.Button(
"Ajouter un élément de notation",
id=f"add-element-{n_clicks}",
className="add-element",
),
],
className="exercise",
)
children.append(new_element)
return children
@app.callback(
dash.dependencies.Output("output", "children"),
dash.dependencies.Input(
{"type": "exercice", "index": dash.dependencies.ALL}, "value"
),
)
def display_output(exercices):
return html.Div([html.P(f"{value}") for (i, value) in enumerate(exercices)])
# @app.callback(
# dash.dependencies.Output("exam_store", "data"),
# )
# def update_exam_store():
# pass