diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index 1115a5f..96652f5 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -4,6 +4,7 @@ import json +import random import re import uuid from datetime import datetime @@ -80,6 +81,7 @@ async def start_quiz( captcha_enabled: bool = True, custom_field: str | None = None, cqcs_enabled: bool = False, + randomize_answers: bool = False, user: User = Depends(get_current_user), ): try: @@ -101,6 +103,10 @@ async def start_quiz( game_pin = randint(100000, 999999) game = await redis.get(f"game:{game_pin}") + if randomize_answers: + for question in quiz.questions: + random.shuffle(question["answers"]) + game = PlayGame( quiz_id=quiz_id, game_pin=str(game_pin), diff --git a/frontend/src/lib/dashboard/start_game.svelte b/frontend/src/lib/dashboard/start_game.svelte index 9c97062..289612b 100644 --- a/frontend/src/lib/dashboard/start_game.svelte +++ b/frontend/src/lib/dashboard/start_game.svelte @@ -21,6 +21,7 @@ SPDX-License-Identifier: MPL-2.0 let loading = false; let custom_field = ''; let cqcs_enabled = false; + let randomized_answers = false; const tippy = createTippy({ arrow: true, @@ -39,6 +40,7 @@ SPDX-License-Identifier: MPL-2.0 loading = true; localStorage.setItem('custom_field', custom_field); const cqcs_enabled_parsed = cqcs_enabled ? 'True' : 'False'; + const randomized_answers_parsed = randomized_answers ? 'True' : 'False'; if (captcha_enabled && captcha_selected) { res = await fetch( `/api/v1/quiz/start/${id}?captcha_enabled=True&game_mode=${selected_game_mode}&custom_field=${custom_field}&cqcs_enabled=${cqcs_enabled_parsed}`, @@ -48,7 +50,7 @@ SPDX-License-Identifier: MPL-2.0 ); } else { res = await fetch( - `/api/v1/quiz/start/${id}?captcha_enabled=False&game_mode=${selected_game_mode}&custom_field=${custom_field}&cqcs_enabled=${cqcs_enabled_parsed}`, + `/api/v1/quiz/start/${id}?captcha_enabled=False&game_mode=${selected_game_mode}&custom_field=${custom_field}&cqcs_enabled=${cqcs_enabled_parsed}&randomize_answers=${randomized_answers_parsed}`, { method: 'POST' } @@ -173,6 +175,23 @@ SPDX-License-Identifier: MPL-2.0 > +
+ +