71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
|
#!/usr/bin/env python
|
||
|
# encoding: utf-8
|
||
|
|
||
|
|
||
|
from PyInquirer import prompt, print_json
|
||
|
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)
|
||
|
question = [
|
||
|
{"type": "confirm", "name": "confirm", "message": "C'est bon?(enter)"}
|
||
|
]
|
||
|
while not prompt(question)["confirm"]:
|
||
|
ans = func(ans)
|
||
|
return ans
|
||
|
|
||
|
return wrapper
|
||
|
|
||
|
|
||
|
@prompt_until_validate
|
||
|
def prompt_exam(default={}):
|
||
|
""" Prompt questions to edit an exam """
|
||
|
questions = [
|
||
|
{
|
||
|
"type": "list",
|
||
|
"name": "_tribe",
|
||
|
"message": "Nom de la classe",
|
||
|
"choices": [t["name"] for t in config["tribes"]],
|
||
|
"default": default.get("tribe", ""),
|
||
|
},
|
||
|
{
|
||
|
"type": "input",
|
||
|
"name": "type",
|
||
|
"message": "Type d'évaluation",
|
||
|
"default": default.get("type", "DS"),
|
||
|
},
|
||
|
{
|
||
|
"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")),
|
||
|
},
|
||
|
{
|
||
|
"type": "input",
|
||
|
"name": "ExQty",
|
||
|
"message": "Nombre d'exercice",
|
||
|
"validate": lambda x: x.isdigit(),
|
||
|
"default": default.get("ExQty", "1"),
|
||
|
},
|
||
|
]
|
||
|
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
|
||
|
|
||
|
|
||
|
def prompt_exercise(number=1):
|
||
|
pass
|
||
|
|
||
|
|
||
|
def prompt_question():
|
||
|
pass
|