From 5e7f4d8872f2bf3ba2b044261fe21c4605780aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Setni=C4=8Dka?= <setnicka@seznam.cz> Date: Mon, 11 Jan 2021 19:32:52 +0100 Subject: [PATCH] =?UTF-8?q?Po=C4=8D=C3=ADtadla=20=C5=99e=C5=A1en=C3=AD=20t?= =?UTF-8?q?ak=C3=A9=20na=20str=C3=A1nce=20kola=20u=20v=C3=BDpisu=20=C3=BAl?= =?UTF-8?q?oh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spočítání by mělo být díky indexům snad levné. --- mo/web/org_round.py | 14 ++++++++++++++ mo/web/templates/org_round.html | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/mo/web/org_round.py b/mo/web/org_round.py index 80c95480..f3cda38b 100644 --- a/mo/web/org_round.py +++ b/mo/web/org_round.py @@ -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(): diff --git a/mo/web/templates/org_round.html b/mo/web/templates/org_round.html index a50c55ee..53cf0e13 100644 --- a/mo/web/templates/org_round.html +++ b/mo/web/templates/org_round.html @@ -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> -- GitLab