From 918f7314fc025238a19bff644150b8c9f24f1def Mon Sep 17 00:00:00 2001 From: Mawoka Date: Mon, 30 Oct 2023 19:22:14 +0100 Subject: [PATCH] :bug: Fixed Excel Import --- classquiz/helpers/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classquiz/helpers/__init__.py b/classquiz/helpers/__init__.py index 388b3c4..fbb8f8a 100644 --- a/classquiz/helpers/__init__.py +++ b/classquiz/helpers/__init__.py @@ -132,10 +132,10 @@ async def handle_import_from_excel(data: BinaryIO, user: User) -> Quiz: if row[0] is None: continue question = row[0] - if len(question) > 200: - raise HTTPException(status_code=400, detail=f"Question {i + 1} is longer than 200") + if len(question) > 300: + raise HTTPException(status_code=400, detail=f"Question {i + 1} is longer than 300") try: - time = int(row[5]) + time = int(str(row[5]).partition(".")[0]) except (ValueError, TypeError): raise HTTPException(status_code=400, detail=f"Time in q {i + 1} isn't a valid int") if time > 120: @@ -143,7 +143,6 @@ async def handle_import_from_excel(data: BinaryIO, user: User) -> Quiz: answers = [row[1], row[2], row[3], row[4]] for a, answer in enumerate(answers): if answer is None: - answers.pop(a) continue if len(answer) > 150: raise HTTPException(status_code=400, detail=f"Answer {a + 1} in Question {i + 1} is longer than 150") @@ -152,6 +151,8 @@ async def handle_import_from_excel(data: BinaryIO, user: User) -> Quiz: correct_answers: str = str(row[6]) answers_list: list[ABCDQuizAnswer] = [] for a, answer in enumerate(answers): + if answer is None: + continue answers_list.append(ABCDQuizAnswer(answer=answer, right=str(a + 1) in correct_answers)) questions.append(QuizQuestion(question=question, answers=answers_list, time=str(time)).dict()) existing_quiz: Quiz | None = await Quiz.objects.get_or_none(user_id=user, title=title)