Feat: Questionnary is ok

This commit is contained in:
Bertrand Benjamin 2020-01-22 21:38:52 +01:00
parent 7d2cde304d
commit 33117cde71

View File

@ -8,113 +8,130 @@ from PyInquirer import prompt, print_json
from .config import config from .config import config
class PromptAbortException(EOFError):
def __init__(self, message, errors=None):
# Call the base class constructor with the parameters it needs
super(PromptAbortException, self).__init__("Abort questionnary", errors)
def get_tribes(answers):
""" List tribes based on subdirectory of config["source"] which have an "eleves.csv" file inside """
return [
p.name for p in Path(config["source"]).iterdir() if (p / "eleves.csv").exists()
]
def prepare_csv(): def prepare_csv():
items = new_eval()
def new_eval(answers={}):
click.echo(f"Préparation d'un nouveau devoir") click.echo(f"Préparation d'un nouveau devoir")
eval_questions = [ eval_questions = [
{"type": "input", "name": "evalname", "message": "Nom de l'évaluation",},
{ {
"type": "input", "type": "list",
"name": "evalname",
"message": "Nom de l'évaluation",
},
{
"type": "input",
"name": "tribe", "name": "tribe",
"message": "Classe concernée", "message": "Classe concernée",
"choices": get_tribes,
}, },
{ {
"type": "input", "type": "input",
"name": "date", "name": "date",
"message": "Date du devoir", "message": "Date du devoir (%y%m%d)",
"filter": lambda val: datetime.strptime(val, "%y%m%d") "default": datetime.today().strftime("%y%m%d"),
"filter": lambda val: datetime.strptime(val, "%y%m%d"),
}, },
{ {
"type": "list", "type": "list",
"name": "term", "name": "term",
"message": "Trimestre", "message": "Trimestre",
"choices": ["1", "2", "3"], "choices": ["1", "2", "3"],
} },
] ]
eval_ans = prompt(eval_questions)
items = []
add_exo = True
while add_exo:
ex_items = new_exercice(eval_ans)
items += ex_items
add_exo = prompt(
[
{
"type": "confirm",
"name": "add_exo",
"message": "Ajouter un autre exercice",
"default": True,
}
]
)["add_exo"]
return items
def new_exercice(answers={}):
exercise_questions = [ exercise_questions = [
{ {"type": "input", "name": "exercisename", "message": "Nom de l'exercice"},
"type": "input",
"name": "exercisename",
"message": "Nom de l'exercice"
},
] ]
click.echo(f"Nouvel exercice")
exercise_ans = prompt(exercise_questions, answers=answers)
items = []
add_item = True
while add_item:
try:
item_ans = new_item(exercise_ans)
except PromptAbortException:
click.echo("Création de l'item annulée")
else:
items.append(item_ans)
add_item = prompt(
[
{
"type": "confirm",
"name": "add_item",
"message": f"Ajouter un autre item pour l'exercice {exercise_ans['exercisename']}",
"default": True,
}
]
)["add_item"]
return items
def new_item(answers={}):
item_questions = [ item_questions = [
{ {"type": "input", "name": "itemname", "message": "Nom de l'item",},
"type": "input", {"type": "input", "name": "comment", "message": "Description",},
"name": "itemname",
"message": "Nom de l'item",
},
{
"type": "input",
"name": "comment",
"message": "Description",
},
{ {
"type": "list", "type": "list",
"name": "competence", "name": "competence",
"message": "Competence", "message": "Competence",
"choices": ["Cher", "Rep", "Mod", "Rai", "Cal", "Com"], "choices": ["Cher", "Rep", "Mod", "Rai", "Cal", "Com"],
}, },
{ {"type": "input", "name": "domain", "message": "Domaine",},
"type": "input",
"name": "domain",
"message": "Domaine",
},
{ {
"type": "confirm", "type": "confirm",
"name": "is_leveled", "name": "is_leveled",
"message": "Évaluation par niveau", "message": "Évaluation par niveau",
"default": True "default": True,
},
{
"type": "input",
"name": "scorerate",
"message": "Bareme"
}, },
{"type": "input", "name": "scorerate", "message": "Bareme"},
{ {
"type": "confirm", "type": "confirm",
"name": "correct", "name": "correct",
"message": "Tout est correct?", "message": "Tout est correct?",
"default": True
},
{
"type": "confirm",
"name": "add_item",
"message": "Ajouter un autre item",
"default": True, "default": True,
}, },
] ]
click.echo(f"Nouvelle question pour l'exercice {answers['exercisename']}")
eval_ans = prompt(eval_questions) item_ans = prompt(item_questions, answers=answers)
if item_ans["correct"]:
return item_ans
items = [] raise PromptAbortException("Abort item creation")
add_exo = True
while add_exo:
click.echo(f"Nouvel exercice")
exercise_ans = prompt(exercise_questions)
add_item = True
while add_item:
click.echo(f"Nouvelle question pour l'exercice {exercise_ans['exercisename']}")
item_ans = prompt(item_questions)
if item_ans["correct"]:
add_item = item_ans["add_item"]
item_ans.update(eval_ans)
item_ans.update(exercise_ans)
items.append(item_ans)
add_exo = prompt([{
"type": "confirm",
"name": "add_exo",
"message": "Ajouter un autre exercice",
"default": True
}])["add_exo"]
return items