feature: handle SWL questions
This commit is contained in:
+26
-2
@@ -26,10 +26,32 @@ class Build:
|
||||
self.env.filters["shuffle_answers"] = self.__filter_shuffle_answers
|
||||
with self.config.p_data_fragenkatalog.open(encoding="utf-8") as file:
|
||||
self.fragenkatalog = json.load(file)
|
||||
|
||||
supplemental_questions = {}
|
||||
if self.config.p_data_fragenkatalog_swl.exists():
|
||||
with self.config.p_data_fragenkatalog_swl.open(encoding="utf-8") as file:
|
||||
swl_fragenkatalog = json.load(file)
|
||||
supplemental_questions = self.__parse_katalog(swl_fragenkatalog)
|
||||
self.fragenkatalog["sections"].extend(swl_fragenkatalog.get("sections", []))
|
||||
|
||||
with self.config.p_data_metadata.open(encoding="utf-8") as file:
|
||||
self.question_metadata = json.load(file)
|
||||
self.questions = self.__parse_katalog(self.fragenkatalog)
|
||||
|
||||
for number in supplemental_questions:
|
||||
self.question_metadata.setdefault(
|
||||
number,
|
||||
{
|
||||
"directus_id": "",
|
||||
"picture_question": "",
|
||||
"picture_a": "",
|
||||
"picture_b": "",
|
||||
"picture_c": "",
|
||||
"picture_d": "",
|
||||
"layout": "",
|
||||
},
|
||||
)
|
||||
|
||||
self.question_index = {}
|
||||
self.question_token_pattern = re.compile(r"^\s*\[question:([\w\d]+)\]", re.MULTILINE)
|
||||
|
||||
@@ -143,8 +165,10 @@ class Build:
|
||||
|
||||
def __build_exam_simulator(self):
|
||||
self.config.p_build_assets.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(self.config.p_data_fragenkatalog, self.config.p_build_assets / "fragenkatalog.json")
|
||||
shutil.copyfile(self.config.p_data_metadata, self.config.p_build_assets / "metadata.json")
|
||||
with (self.config.p_build_assets / "fragenkatalog.json").open("w", encoding="utf-8") as file:
|
||||
json.dump(self.fragenkatalog, file, ensure_ascii=False, indent=4)
|
||||
with (self.config.p_build_assets / "metadata.json").open("w", encoding="utf-8") as file:
|
||||
json.dump(self.question_metadata, file, ensure_ascii=False, indent=4)
|
||||
(self.config.p_build_assets / "exam-questions.json").unlink(missing_ok=True)
|
||||
|
||||
picture_fields = ("picture_question", "picture_a", "picture_b", "picture_c", "picture_d")
|
||||
|
||||
Reference in New Issue
Block a user