Feat: prompt for exercises
This commit is contained in:
parent
49cc52f7d1
commit
5e0f2d92ef
@ -2,7 +2,7 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
|
||||||
from PyInquirer import prompt, print_json
|
from PyInquirer import prompt
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -13,9 +13,7 @@ def prompt_until_validate(func):
|
|||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwrd):
|
def wrapper(*args, **kwrd):
|
||||||
ans = func(*args, **kwrd)
|
ans = func(*args, **kwrd)
|
||||||
question = [
|
question = [{"type": "confirm", "name": "confirm", "message": "C'est bon?"}]
|
||||||
{"type": "confirm", "name": "confirm", "message": "C'est bon?(enter)"}
|
|
||||||
]
|
|
||||||
while not prompt(question)["confirm"]:
|
while not prompt(question)["confirm"]:
|
||||||
ans = func(ans)
|
ans = func(ans)
|
||||||
return ans
|
return ans
|
||||||
@ -24,35 +22,35 @@ def prompt_until_validate(func):
|
|||||||
|
|
||||||
|
|
||||||
@prompt_until_validate
|
@prompt_until_validate
|
||||||
def prompt_exam(default={}):
|
def prompt_exam(**kwrd):
|
||||||
""" Prompt questions to edit an exam """
|
""" Prompt questions to edit an exam """
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
|
"message": "Nom de la classe",
|
||||||
"type": "list",
|
"type": "list",
|
||||||
"name": "_tribe",
|
"name": "_tribe",
|
||||||
"message": "Nom de la classe",
|
|
||||||
"choices": [t["name"] for t in config["tribes"]],
|
"choices": [t["name"] for t in config["tribes"]],
|
||||||
"default": default.get("tribe", ""),
|
"default": kwrd.get("tribe", ""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"message": "Type d'évaluation",
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"name": "type",
|
"name": "type",
|
||||||
"message": "Type d'évaluation",
|
"default": kwrd.get("type", "DS"),
|
||||||
"default": default.get("type", "DS"),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"message": "Date (%y%m%d)",
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"name": "_date",
|
"name": "_date",
|
||||||
"message": "Date (%y%m%d)",
|
|
||||||
"validate": lambda x: (len(x) == 6) and x.isdigit(),
|
"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",
|
"type": "input",
|
||||||
"name": "ExQty",
|
"name": "ExQty",
|
||||||
"message": "Nombre d'exercice",
|
|
||||||
"validate": lambda x: x.isdigit(),
|
"validate": lambda x: x.isdigit(),
|
||||||
"default": default.get("ExQty", "1"),
|
"default": kwrd.get("ExQty", "1"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
exam = prompt(questions)
|
exam = prompt(questions)
|
||||||
@ -62,8 +60,30 @@ def prompt_exam(default={}):
|
|||||||
return exam
|
return exam
|
||||||
|
|
||||||
|
|
||||||
def prompt_exercise(number=1):
|
@prompt_until_validate
|
||||||
pass
|
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():
|
def prompt_question():
|
||||||
|
@ -8,7 +8,7 @@ import papermill as pm
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from .getconfig import config
|
from .getconfig import config
|
||||||
from .prompts import prompt_exam
|
from .prompts import prompt_exam, prompt_exercise
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@ -36,6 +36,10 @@ def setup():
|
|||||||
def new_exam():
|
def new_exam():
|
||||||
""" Create new exam csv file """
|
""" Create new exam csv file """
|
||||||
exam = prompt_exam()
|
exam = prompt_exam()
|
||||||
|
exam["exercices"] = []
|
||||||
|
for ex in range(int(exam["ExQty"])):
|
||||||
|
exam["exercices"].append(prompt_exercise(ex + 1))
|
||||||
|
print(exam)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
Loading…
Reference in New Issue
Block a user