From 5e0f2d92efcc1003a2b12ba0288a8ffd3fef05a4 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 4 Oct 2020 16:38:36 +0200 Subject: [PATCH] Feat: prompt for exercises --- recopytex/scripts/prompts.py | 50 ++++++++++++++++++++++++---------- recopytex/scripts/recopytex.py | 6 +++- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/recopytex/scripts/prompts.py b/recopytex/scripts/prompts.py index 81991e3..523d1ef 100644 --- a/recopytex/scripts/prompts.py +++ b/recopytex/scripts/prompts.py @@ -2,7 +2,7 @@ # encoding: utf-8 -from PyInquirer import prompt, print_json +from PyInquirer import prompt from datetime import datetime from functools import wraps @@ -13,9 +13,7 @@ def prompt_until_validate(func): @wraps(func) def wrapper(*args, **kwrd): ans = func(*args, **kwrd) - question = [ - {"type": "confirm", "name": "confirm", "message": "C'est bon?(enter)"} - ] + question = [{"type": "confirm", "name": "confirm", "message": "C'est bon?"}] while not prompt(question)["confirm"]: ans = func(ans) return ans @@ -24,35 +22,35 @@ def prompt_until_validate(func): @prompt_until_validate -def prompt_exam(default={}): +def prompt_exam(**kwrd): """ Prompt questions to edit an exam """ questions = [ { + "message": "Nom de la classe", "type": "list", "name": "_tribe", - "message": "Nom de la classe", "choices": [t["name"] for t in config["tribes"]], - "default": default.get("tribe", ""), + "default": kwrd.get("tribe", ""), }, { + "message": "Type d'évaluation", "type": "input", "name": "type", - "message": "Type d'évaluation", - "default": default.get("type", "DS"), + "default": kwrd.get("type", "DS"), }, { + "message": "Date (%y%m%d)", "type": "input", "name": "_date", - "message": "Date (%y%m%d)", "validate": lambda x: (len(x) == 6) and x.isdigit(), - "default": default.get("_date", datetime.today().strftime("%y%m%d")), + "default": kwrd.get("_date", datetime.today().strftime("%y%m%d")), }, { + "message": "Nombre d'exercice", "type": "input", "name": "ExQty", - "message": "Nombre d'exercice", "validate": lambda x: x.isdigit(), - "default": default.get("ExQty", "1"), + "default": kwrd.get("ExQty", "1"), }, ] exam = prompt(questions) @@ -62,8 +60,30 @@ def prompt_exam(default={}): return exam -def prompt_exercise(number=1): - pass +@prompt_until_validate +def prompt_exercise(number=1, **kwrd): + questions = [ + { + "message": "Nom de l'exercice", + "type": "input", + "name": "name", + "default": kwrd.get("name", f"Exercice {number}"), + } + ] + exercise = prompt(questions) + exercise["questions"] = [] + + append = [ + { + "message": "Ajouter un élément de notation", + "type": "confirm", + "name": "append", + } + ] + while prompt(append)["append"]: + exercise["questions"].append(prompt_question()) + + return exercise def prompt_question(): diff --git a/recopytex/scripts/recopytex.py b/recopytex/scripts/recopytex.py index 422fa5e..5f7f7d0 100644 --- a/recopytex/scripts/recopytex.py +++ b/recopytex/scripts/recopytex.py @@ -8,7 +8,7 @@ import papermill as pm from datetime import datetime from .getconfig import config -from .prompts import prompt_exam +from .prompts import prompt_exam, prompt_exercise @click.group() @@ -36,6 +36,10 @@ def setup(): def new_exam(): """ Create new exam csv file """ exam = prompt_exam() + exam["exercices"] = [] + for ex in range(int(exam["ExQty"])): + exam["exercices"].append(prompt_exercise(ex + 1)) + print(exam) @cli.command()