diff --git a/webapp/dto.py b/webapp/dto.py index 80fae584..b55a12b8 100644 --- a/webapp/dto.py +++ b/webapp/dto.py @@ -170,6 +170,16 @@ def show_achievements(self) -> bool: Status.CheckedFailed: True, }) + @property + def is_submitted(self) -> bool: + if self.status in [Status.Submitted, Status.CheckedSubmitted]: + return True + if self.status in [Status.Checked, Status.Failed, Status.NotSubmitted, Status.CheckedFailed]: + return False + else: + assert False, "unhandled status" + return False + def map_achievements(self, status: TaskStatus | None, achievements: list[int]): dtos = [] for order, count in enumerate(achievements): diff --git a/webapp/static/js/autoreload.js b/webapp/static/js/autoreload.js new file mode 100644 index 00000000..70d4ca1d --- /dev/null +++ b/webapp/static/js/autoreload.js @@ -0,0 +1,13 @@ +let statusPath = window.location.href + "/status"; +let f = () => fetch(statusPath).then(res => { + if(res.status == 418) { + return new Promise(r => setTimeout(r, 2000)).then(f) + } + if(!res.ok) { + return + } + return res.text().then(b => { + document.getElementById("task-status").innerHTML = b; + }) +}); +f() diff --git a/webapp/templates/student/task.jinja b/webapp/templates/student/task.jinja index faef0645..a575eb6e 100644 --- a/webapp/templates/student/task.jinja +++ b/webapp/templates/student/task.jinja @@ -28,48 +28,14 @@ status.external.group_title }} -
-
- Состояние задачи -
-
- В данной секции Вы можете отслеживать состояние задания после отправки решения. -
- {% if status.status == 4 %} - {% else %} -
- {{ status.name }} -
- {% if status.error_message is not none and status.error_message and (not registration or student) %} -
Подробные сведения об ошибке:
-
{{ status.error_message | e }}
- {% else %} -
- {% endif %} - {% endif %} -
-{% if status.show_achievements %} -
-
- Разблокированные достижения - - {{ status.earned }} из {{ status.achievements | length }} - -
-
- Сможете ли Вы решить задачу всеми способами, известными искусственной нейронной сети? -
- {% if status.achievements %} - {% for dto in status.achievements %} -
-
{{ dto.title }} {{ '✓' if dto.active else '' }}
- {{ dto.description }} -
- {% endfor %} - {% endif %} -
+ +{% if status.is_submitted %} + {% endif %} +
+{% include 'student/task_status.jinja' %} +
+
Добавить новый ответ
diff --git a/webapp/templates/student/task_status.jinja b/webapp/templates/student/task_status.jinja new file mode 100644 index 00000000..7f9d0057 --- /dev/null +++ b/webapp/templates/student/task_status.jinja @@ -0,0 +1,42 @@ +
+
+ Состояние задачи +
+
+ В данной секции Вы можете отслеживать состояние задания после отправки решения. +
+ {% if status.status == 4 %} + {% else %} +
+ {{ status.name }} +
+ {% if status.error_message is not none and status.error_message and (not registration or student) %} +
Подробные сведения об ошибке:
+
{{ status.error_message | e }}
+ {% else %} +
+ {% endif %} + {% endif %} +
+{% if status.show_achievements %} +
+
+ Разблокированные достижения + + {{ status.earned }} из {{ status.achievements | length }} + +
+
+ Сможете ли Вы решить задачу всеми способами, известными искусственной нейронной сети? +
+ {% if status.achievements %} + {% for dto in status.achievements %} +
+
{{ dto.title }} {{ '✓' if dto.active else '' }}
+ {{ dto.description }} +
+ {% endfor %} + {% endif %} +
+{% endif %} diff --git a/webapp/views/student.py b/webapp/views/student.py index 8f4f8087..1f99b3ad 100644 --- a/webapp/views/student.py +++ b/webapp/views/student.py @@ -14,7 +14,7 @@ from webapp.forms import StudentChangePasswordForm, StudentLoginForm, StudentMessageForm, StudentRegisterForm from webapp.managers import AppConfigManager, GroupManager, HomeManager, StatusManager, StudentManager -from webapp.models import Student +from webapp.models import Status, Student from webapp.repositories import AppDatabase from webapp.utils import authorize, get_exception_info, get_greeting_msg, get_real_ip, logout @@ -232,14 +232,7 @@ def submit_task(student: Student | None, gid: int, vid: int, tid: int): session_id = request.cookies.get("anonymous_identifier") db.messages.submit_task(tid, vid, gid, form.code.data, ip, sid, session_id) db.statuses.submit_task(tid, vid, gid, form.code.data, ip) - return render_template( - "student/success.jinja", - status=status, - registration=config.config.registration, - group_rating=config.config.groups, - exam=config.config.exam, - student=student, - ) + return redirect(f"/group/{gid}/variant/{vid}/task/{tid}") return render_template( "student/task.jinja", highlight=config.config.highlight_syntax, @@ -252,6 +245,25 @@ def submit_task(student: Student | None, gid: int, vid: int, tid: int): ) +@blueprint.route('/group//variant//task//status', methods=["GET"]) +@authorize(db.students) +def task_status(student: Student | None, gid: int, vid: int, tid: int): + if config.config.registration and not student: + return redirect("/login") + if student and not student.teacher and student.group != gid: + return redirect("/") + status = statuses.get_task_status(gid, vid, tid) + if not status.is_submitted: + return render_template( + "student/task_status.jinja", + registration=config.config.registration, + status=status, + student=student, + ) + else: + return ('', 418) + + @blueprint.route("/files/task//group/", methods=["GET"]) @authorize(db.students) def files(student: Student | None, tid: int, gid: int):