Skip to content
Snippets Groups Projects
Commit 5e7f4d88 authored by Jiří Setnička's avatar Jiří Setnička
Browse files

Počítadla řešení také na stránce kola u výpisu úloh

Spočítání by mělo být díky indexům snad levné.
parent 78ee2124
No related branches found
No related tags found
1 merge request!9WIP: Zárodek uživatelské části webu a submitování
......@@ -4,6 +4,7 @@ import locale
import os
import secrets
from flask_wtf.form import FlaskForm
from sqlalchemy import func
from sqlalchemy.orm import joinedload
import werkzeug.exceptions
import wtforms
......@@ -66,8 +67,21 @@ def org_round(id: int):
contests.sort(key=lambda c: locale.strxfrm(c.place.name))
sol_counts_q = (
sess.query(db.Solution.task_id, func.count(db.Solution.task_id))
.filter(db.Solution.task_id.in_(
sess.query(db.Task.task_id).filter_by(round=round)
))
)
sol_counts = {}
for task_id, count in sol_counts_q.group_by(db.Solution.task_id).all():
sol_counts[task_id] = count
tasks = sess.query(db.Task).filter_by(round=round).all()
tasks.sort(key=lambda t: t.code)
for task in tasks:
task.sol_count = sol_counts[task.task_id] if task.task_id in sol_counts else 0
form_delete_task = TaskDeleteForm()
if can_manage_contestants and form_delete_task.validate_on_submit():
......
......@@ -44,15 +44,17 @@
<table class=data>
<thead>
<tr>
<th>Kód</th>
<th>Název</th>
{% if can_manage_round %}<th>Akce</th>{% endif %}
<th>Kód
<th>Název
<th>Odevzdaná řešení
{% if can_manage_round %}<th>Akce{% endif %}
</tr>
</thead>
{% for task in tasks %}
<tr>
<td>{{ task.code }}</td>
<td>{{ task.name }}</td>
<td>{{ task.code }}
<td>{{ task.name }}
<td>{{ task.sol_count }}
{% if can_manage_round %}<td>
<form action="" method="POST" onsubmit="return confirm('Opravdu nenávratně smazat?')" class="btn-group">
{{ form_delete_task.csrf_token() }}
......@@ -60,7 +62,7 @@
<a class="btn btn-xs btn-primary" href="{{ url_for('org_round_task_edit', id=round.round_id, task_id=task.task_id) }}">Editovat</a>
<button type="submit" class="btn btn-xs btn-danger">Smazat</button>
</form>
</td>{% endif %}
{% endif %}
</tr>
{% endfor %}
</table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment