Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions webapp/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions webapp/static/js/autoreload.js
Original file line number Diff line number Diff line change
@@ -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()
48 changes: 7 additions & 41 deletions webapp/templates/student/task.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,14 @@
status.external.group_title }}
</a>
</div>
<div>
<h6 class="card-title fw-bold">
Состояние задачи
</h6>
<h6 class="card-subtitle mb-2 text-muted">
В данной секции Вы можете отслеживать состояние задания после отправки решения.
</h6>
{% if status.status == 4 %}
{% else %}
<div class="badge alert-{{ status.color }} mt-2 mb-2" style="font-size: inherit">
{{ status.name }}
</div>
{% if status.error_message is not none and status.error_message and (not registration or student) %}
<div>Подробные сведения об ошибке:</div>
<div class="text-muted mb-2" style="white-space: pre-wrap">{{ status.error_message | e }}</div>
{% else %}
<div class="mb-2"></div>
{% endif %}
{% endif %}
</div>
{% if status.show_achievements %}
<div>
<h6 class="card-title fw-bold">
Разблокированные достижения
<small class="text-muted">
{{ status.earned }} из {{ status.achievements | length }}
</small>
</h6>
<h6 class="card-subtitle mb-2 text-muted">
Сможете ли Вы решить задачу всеми способами, известными <a class="text-decoration-none"
href="https://github.com/true-grue/kispython/blob/main/contrib/elm.ipynb">искусственной нейронной сети</a>?
</h6>
{% if status.achievements %}
{% for dto in status.achievements %}
<div class="callout callout-{{ 'success' if dto.active else 'default text-muted' }}">
<div>{{ dto.title }} {{ '✓' if dto.active else '' }}</div>
<small>{{ dto.description }}</small>
</div>
{% endfor %}
{% endif %}
</div>

{% if status.is_submitted %}
<script src="/static/js/autoreload.js"></script>
{% endif %}
<div id="task-status">
{% include 'student/task_status.jinja' %}
</div>

<div class="card m-auto mt-3 mb-5">
<form class="card-body" action="{{ status.submission_url }}" method="POST">
<h6 class="card-title fw-bold mb-0">Добавить новый ответ</h6>
Expand Down
42 changes: 42 additions & 0 deletions webapp/templates/student/task_status.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div>
<h6 class="card-title fw-bold">
Состояние задачи
</h6>
<h6 class="card-subtitle mb-2 text-muted">
В данной секции Вы можете отслеживать состояние задания после отправки решения.
</h6>
{% if status.status == 4 %}
{% else %}
<div class="badge alert-{{ status.color }} mt-2 mb-2" style="font-size: inherit">
{{ status.name }}
</div>
{% if status.error_message is not none and status.error_message and (not registration or student) %}
<div>Подробные сведения об ошибке:</div>
<div class="text-muted mb-2" style="white-space: pre-wrap">{{ status.error_message | e }}</div>
{% else %}
<div class="mb-2"></div>
{% endif %}
{% endif %}
</div>
{% if status.show_achievements %}
<div>
<h6 class="card-title fw-bold">
Разблокированные достижения
<small class="text-muted">
{{ status.earned }} из {{ status.achievements | length }}
</small>
</h6>
<h6 class="card-subtitle mb-2 text-muted">
Сможете ли Вы решить задачу всеми способами, известными <a class="text-decoration-none"
href="https://github.com/true-grue/kispython/blob/main/contrib/elm.ipynb">искусственной нейронной сети</a>?
</h6>
{% if status.achievements %}
{% for dto in status.achievements %}
<div class="callout callout-{{ 'success' if dto.active else 'default text-muted' }}">
<div>{{ dto.title }} {{ '✓' if dto.active else '' }}</div>
<small>{{ dto.description }}</small>
</div>
{% endfor %}
{% endif %}
</div>
{% endif %}
30 changes: 21 additions & 9 deletions webapp/views/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -252,6 +245,25 @@ def submit_task(student: Student | None, gid: int, vid: int, tid: int):
)


@blueprint.route('/group/<int:gid>/variant/<int:vid>/task/<int:tid>/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/<int:tid>/group/<int:gid>", methods=["GET"])
@authorize(db.students)
def files(student: Student | None, tid: int, gid: int):
Expand Down