Fix: can't save in create exam

This commit is contained in:
Bertrand Benjamin 2021-05-10 12:21:42 +02:00
parent 1ffdd8676b
commit 29f67cfa0c

View File

@ -3,7 +3,8 @@
from datetime import datetime
from pathlib import Path
from prompt_toolkit import HTML
# from prompt_toolkit import HTML
from ..config import NO_ST_COLUMNS
import pandas as pd
import yaml
@ -57,11 +58,13 @@ class Exam:
return self._term
def add_exercise(self, name, questions):
""" Add key with questions in ._exercises """
"""Add key with questions in ._exercises"""
try:
self._exercises[name]
except KeyError:
self._exercises[name] = format_question(questions)
self._exercises[name] = [
format_question(question) for question in questions
]
else:
raise KeyError("The exercise already exsists. Use modify_exercise")
@ -100,7 +103,7 @@ class Exam:
@property
def long_name(self):
""" Get exam name with date inside """
"""Get exam name with date inside"""
return f"{self.date.strftime('%y%m%d')}_{self.name}"
def path(self, extention=""):
@ -153,6 +156,7 @@ class Exam:
def write_csv(self):
rows = self.to_row()
print(rows)
base_df = pd.DataFrame.from_dict(rows)[NO_ST_COLUMNS.keys()]
base_df.rename(columns=NO_ST_COLUMNS, inplace=True)
@ -173,7 +177,7 @@ class Exam:
@property
def competences_rate(self):
""" Dictionnary with competences as key and total rate as value"""
"""Dictionnary with competences as key and total rate as value"""
rates = {}
for ex, questions in self._exercises.items():
for q in questions:
@ -190,7 +194,7 @@ class Exam:
@property
def themes_rate(self):
""" Dictionnary with themes as key and total rate as value"""
"""Dictionnary with themes as key and total rate as value"""
rates = {}
for ex, questions in self._exercises.items():
for q in questions: