Feat: prompt for exercises
This commit is contained in:
parent
49cc52f7d1
commit
5e0f2d92ef
@ -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():
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user