From 95fc842c1d71e120addbf2f860eaa6a857e07274 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Thu, 21 Jan 2021 13:53:16 +0100 Subject: [PATCH] Feat: 2nd page to create exam --- recopytex/dashboard/create_exam/__init__.py | 0 recopytex/dashboard/create_exam/app.py | 164 ++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 recopytex/dashboard/create_exam/__init__.py create mode 100644 recopytex/dashboard/create_exam/app.py diff --git a/recopytex/dashboard/create_exam/__init__.py b/recopytex/dashboard/create_exam/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/recopytex/dashboard/create_exam/app.py b/recopytex/dashboard/create_exam/app.py new file mode 100644 index 0000000..9da0690 --- /dev/null +++ b/recopytex/dashboard/create_exam/app.py @@ -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