Feat: formating questions

This commit is contained in:
Bertrand Benjamin 2021-04-05 08:31:05 +02:00
parent c84f9845b2
commit a0e94f52b1

View File

@ -19,6 +19,11 @@ def try_parsing_date(text, formats=["%Y-%m-%d", "%Y.%m.%d", "%Y/%m/%d"]):
raise ValueError("no valid date format found") raise ValueError("no valid date format found")
def format_question(question):
question["score_rate"] = float(question["score_rate"])
return question
class Exam: class Exam:
def __init__(self, name, tribename, date, term, **kwrds): def __init__(self, name, tribename, date, term, **kwrds):
self._name = name self._name = name
@ -56,7 +61,7 @@ class Exam:
try: try:
self._exercises[name] self._exercises[name]
except KeyError: except KeyError:
self._exercises[name] = questions self._exercises[name] = format_question(questions)
else: else:
raise KeyError("The exercise already exsists. Use modify_exercise") raise KeyError("The exercise already exsists. Use modify_exercise")
@ -72,9 +77,9 @@ class Exam:
raise KeyError("The exercise already exsists. Use modify_exercise") raise KeyError("The exercise already exsists. Use modify_exercise")
else: else:
if append: if append:
self._exercises[name] += questions self._exercises[name] += format_question(questions)
else: else:
self._exercises[name] = questions self._exercises[name] = format_question(questions)
@property @property
def exercices(self): def exercices(self):