🐛 Fix excel import when answer is a number

This commit is contained in:
Marlon
2024-07-14 22:14:36 +02:00
committed by GitHub
parent 2bfd73412d
commit a723ef5a22
+2 -2
View File
@@ -146,7 +146,7 @@ async def handle_import_from_excel(data: BinaryIO, user: User) -> Quiz:
for a, answer in enumerate(answers): for a, answer in enumerate(answers):
if answer is None: if answer is None:
continue continue
if len(answer) > 150: if len(str(answer)) > 150:
raise HTTPException(status_code=400, detail=f"Answer {a + 1} in Question {i + 1} is longer than 150") raise HTTPException(status_code=400, detail=f"Answer {a + 1} in Question {i + 1} is longer than 150")
if len(answers) < 2: if len(answers) < 2:
raise HTTPException(status_code=400, detail=f"Less than 2 answers in Question {i + 1}") raise HTTPException(status_code=400, detail=f"Less than 2 answers in Question {i + 1}")
@@ -155,7 +155,7 @@ async def handle_import_from_excel(data: BinaryIO, user: User) -> Quiz:
for a, answer in enumerate(answers): for a, answer in enumerate(answers):
if answer is None: if answer is None:
continue continue
answers_list.append(ABCDQuizAnswer(answer=answer, right=str(a + 1) in correct_answers)) answers_list.append(ABCDQuizAnswer(answer=str(answer), right=str(a + 1) in correct_answers))
existing_question: dict | None = None existing_question: dict | None = None
if existing_quiz is not None: if existing_quiz is not None: