diff --git a/mo/web/org_round.py b/mo/web/org_round.py index 80c9548084b3160e9977e03a747729f1c1c6aeb0..f3cda38b62d1e6cea85ba27be0670da6aa3adb26 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 a50c55ee929abd5618d58f3c70fd1c271aff1b07..53cf0e1305a99cf31614964bce63666a2665b998 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>