Найдите себя и нажмите получить тест:
++ + +
+ +diff --git a/gui/index.html b/gui/index.html new file mode 100644 index 0000000..da5d27e --- /dev/null +++ b/gui/index.html @@ -0,0 +1,37 @@ + + + +
+ + + + + + +Получите тест
+Найдите себя и нажмите получить тест:
++ + +
+ +${students_selector.options[students_selector.selectedIndex].text}
` + document.getElementById("main").innerHTML = questions_html + + var button = document.createElement('button'); + button.innerHTML = 'Сдать'; + button.onclick = function () { + const form = document.getElementById('form'); + const formData = new FormData(form); + console.log(formData) + for (const [key, value] of formData) { + console.log(quiz) + console.log(`${key}: ${value}\n`) // assume questions are in the same order - can it make code simplier? + quiz.questions.find(q => q.id == key).student_answer = value + // console.log(quiz) + } + fetch('http://localhost:8000/save_student_answers?' + new URLSearchParams({ + student_answers: JSON.stringify(quiz) + })) + document.getElementById("main").innerHTML = "Тестирование окончено
" + }; + // where do we want to have the button to appear? + // you can append it to another element just by doing something like + // document.getElementById('foobutton').appendChild(button); + document.getElementById("main").appendChild(button) + }) + }) + + document.getElementById("end-quiz").addEventListener("click", function() { + let pass = window.prompt("Уважаемый преподаватель, введите пароль, чтобы завершить тестирование для всех", "Я здесь случайно") + // console.log(pass) + fetch('http://localhost:8000/end_quiz?' + new URLSearchParams({ + password: pass + })) + .then(r => r.text()) + .then(text => window.alert(text)) + }) +}) \ No newline at end of file diff --git a/main.py b/main.py index beb05e0..d0af72b 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware # CORS +from fastapi.staticfiles import StaticFiles import json import random from pathlib import Path @@ -64,6 +65,7 @@ def check_answers(student_answers: dict): checked_answers["correct_percent"] = round(checked_answers["correct"] * 100 / len(checked_answers["questions"])) return checked_answers + @app.get("/students") def show_students(): return students @@ -134,4 +136,8 @@ def end_test(password: str): return(f"Тестирование завершено. Сводные результаты сохранены в {results_path.resolve()}") else: return("Неверный пароль") + +app.mount("/", StaticFiles(directory="gui", html = True), name="gui") # must be after method since it uses them + + \ No newline at end of file