2020-10-04 14:11:55 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
|
2020-10-04 14:38:36 +00:00
|
|
|
from PyInquirer import prompt
|
2020-10-04 14:11:55 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
from .getconfig import config
|
|
|
|
|
|
|
|
|
|
|
|
def prompt_until_validate(func):
|
|
|
|
@wraps(func)
|
|
|
|
def wrapper(*args, **kwrd):
|
|
|
|
ans = func(*args, **kwrd)
|
2020-10-04 14:38:36 +00:00
|
|
|
question = [{"type": "confirm", "name": "confirm", "message": "C'est bon?"}]
|
2020-10-04 14:11:55 +00:00
|
|
|
while not prompt(question)["confirm"]:
|
|
|
|
ans = func(ans)
|
|
|
|
return ans
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
@prompt_until_validate
|
2020-10-04 14:38:36 +00:00
|
|
|
def prompt_exam(**kwrd):
|
2020-10-04 14:11:55 +00:00
|
|
|
""" Prompt questions to edit an exam """
|
|
|
|
questions = [
|
|
|
|
{
|
2020-10-04 14:38:36 +00:00
|
|
|
"message": "Nom de la classe",
|
2020-10-04 14:11:55 +00:00
|
|
|
"type": "list",
|
|
|
|
"name": "_tribe",
|
|
|
|
"choices": [t["name"] for t in config["tribes"]],
|
2020-10-04 14:38:36 +00:00
|
|
|
"default": kwrd.get("tribe", ""),
|
2020-10-04 14:11:55 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-04 14:38:36 +00:00
|
|
|
"message": "Type d'évaluation",
|
2020-10-04 14:11:55 +00:00
|
|
|
"type": "input",
|
|
|
|
"name": "type",
|
2020-10-04 14:38:36 +00:00
|
|
|
"default": kwrd.get("type", "DS"),
|
2020-10-04 14:11:55 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-04 14:38:36 +00:00
|
|
|
"message": "Date (%y%m%d)",
|
2020-10-04 14:11:55 +00:00
|
|
|
"type": "input",
|
|
|
|
"name": "_date",
|
|
|
|
"validate": lambda x: (len(x) == 6) and x.isdigit(),
|
2020-10-04 14:38:36 +00:00
|
|
|
"default": kwrd.get("_date", datetime.today().strftime("%y%m%d")),
|
2020-10-04 14:11:55 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-04 14:38:36 +00:00
|
|
|
"message": "Nombre d'exercice",
|
2020-10-04 14:11:55 +00:00
|
|
|
"type": "input",
|
|
|
|
"name": "ExQty",
|
|
|
|
"validate": lambda x: x.isdigit(),
|
2020-10-04 14:38:36 +00:00
|
|
|
"default": kwrd.get("ExQty", "1"),
|
2020-10-04 14:11:55 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
exam = prompt(questions)
|
|
|
|
exam["tribe"] = [t for t in config["tribes"] if exam["_tribe"] == t["name"]][0]
|
|
|
|
exam["date"] = datetime.strptime(exam["_date"], "%y%m%d")
|
|
|
|
|
|
|
|
return exam
|
|
|
|
|
|
|
|
|
2020-10-04 14:38:36 +00:00
|
|
|
@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
|
2020-10-04 14:11:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def prompt_question():
|
|
|
|
pass
|