Skip to content
Snippets Groups Projects
Commit 76a1ab4e authored by Jan Prachař's avatar Jan Prachař
Browse files

org_index: Přehled pro dozory na soutěžním místě

parent 65a23790
No related branches found
No related tags found
No related merge requests found
from dataclasses import dataclass, field
from flask import render_template, redirect, url_for, request, flash, g
from sqlalchemy import and_, or_, tuple_
from sqlalchemy import func, literal, and_, or_, tuple_
from sqlalchemy.orm import aliased, joinedload
from typing import List, Set, Optional, Dict, Tuple
......@@ -19,6 +19,8 @@ class OrgOverview:
round: db.Round
place: db.Place
contest: Optional[db.Contest]
contest_set: Set[db.Contest] = field(default_factory=set)
contest_list: List[db.Contest] = field(default_factory=list)
rights: Optional[mo.rights.Rights] = None
role_set: Set[db.RoleType] = field(default_factory=set)
role_list: List[db.RoleType] = field(default_factory=list)
......@@ -27,6 +29,7 @@ class OrgOverview:
lowest_state: db.RoundState = db.RoundState.closed
num_active_pants: int = 0
num_unconfirmed_pants: int = 0
dozor_place: bool = False
def url_for(self, endpoint):
if self.contest:
......@@ -67,7 +70,7 @@ def org_index():
if add_contest(round, form_add_contest):
return redirect(url_for('org_index'))
rcu = (sess.query(db.Round, db.Contest, db.UserRole)
rcu = (sess.query(db.Round, db.Contest, db.UserRole, literal(0))
.select_from(db.UserRole)
.join(db.Place)
.join(db.Round, and_(db.UserRole.user_id == g.user.user_id,
......@@ -81,8 +84,22 @@ def org_index():
.order_by(db.Place.place_id, db.Round.level, db.Round.category, db.Round.seq, db.Round.part, db.Contest.contest_id)
.all())
rcu += (sess.query(db.Round, db.Contest, db.UserRole, func.count(db.Participation.user_id))
.select_from(db.UserRole)
.join(db.Round, and_(db.UserRole.user_id == g.user.user_id,
or_(db.UserRole.category == None, db.UserRole.category == db.Round.category),
or_(db.UserRole.year == None, db.UserRole.year == db.Round.year),
or_(db.UserRole.seq == None, db.UserRole.seq == db.Round.seq)))
.join(db.Contest, and_(db.Contest.round_id == db.Round.round_id))
.join(db.Participation, and_(db.Participation.contest_id == db.Contest.contest_id, db.Participation.place_id == db.UserRole.place_id, db.Participation.place_id != db.Contest.place_id))
.outerjoin(db.Place, db.Place.place_id == db.UserRole.place_id)
.group_by(db.Round.round_id, db.Contest.contest_id, db.UserRole, db.Place.place_id)
.filter(db.Round.year == config.CURRENT_YEAR)
.order_by(db.UserRole.place_id, db.Round.level, db.Round.category, db.Round.seq, db.Round.part, db.Contest.contest_id)
.all())
overview: List[OrgOverview] = []
for r, ct, ur in rcu:
for r, ct, ur, nap in rcu:
o = overview[-1] if overview else None
if not (o and o.round == r and o.place == ur.place):
o = OrgOverview(round=r, place=ur.place, contest=ct)
......@@ -92,9 +109,13 @@ def org_index():
o.rights = g.gatekeeper.rights_for_round(r, for_place=ur.place)
overview.append(o)
o.role_set.add(ur.role)
if ct and ct not in o.contest_set:
o.num_active_pants += nap
o.contest_set.add(ct)
for o in overview:
o.role_list = sorted(o.role_set, key=lambda r: mo.rights.role_order_by_type[r])
o.contest_list = sorted(o.contest_set, key=lambda ct: ct.place.name)
get_stats(overview)
......@@ -115,8 +136,12 @@ def get_stats(overview: List[OrgOverview]) -> None:
o.contest_states.add(o.contest.state)
if o.contest.state > o.lowest_state:
o.lowest_state = o.contest.state
if o.contest.place_id != o.place.place_id:
o.dozor_place = True
else:
rcs_for.append(rp)
if not o.dozor_place:
rps_for.append(rp)
if rcs_for:
......
......@@ -103,6 +103,13 @@
{% endif %}
<td class="hidden-xs">{% for r in o.role_list %}{{ role_type_names[r] }}{% if not loop.last %}<br>{% endif %}{% endfor %}
<td>
{% if o.dozor_place %}
{% for ct in o.contest_list %}
<a href="{{ url_for('org_contest', ct_id=ct.contest_id, site_id=o.place.place_id) }}" class="btn btn-xs btn-primary">{{ ct.place.name }}</a>
{% if not loop.last %}<br>{% endif %}
{% endfor %}
{% else %}
{% if o.contest or o.round.level > o.place.level %}
<a class="btn btn-xs btn-primary" href='{{ detail_url }}'>Detail</a>
{% if o.num_contests > 0 %}
......@@ -135,6 +142,7 @@
<a class="btn btn-xs btn-warning" href='{{ o.url_for('org_score') }}'>Výsledky</a>
{% endif %}
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
......
......@@ -125,7 +125,7 @@ p > .btn, .panel-body > .btn {
margin-bottom: 5px;
}
tfoot td > .btn-xs {
td > .btn-xs {
margin-top: 2px;
margin-bottom: 2px;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment