From 76a1ab4ee4f465a5dfa1cc606c94f6c2c3571aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pracha=C5=99?= <jan.prachar@gmail.com> Date: Mon, 25 Apr 2022 16:08:00 +0200 Subject: [PATCH] =?UTF-8?q?org=5Findex:=20P=C5=99ehled=20pro=20dozory=20na?= =?UTF-8?q?=20sout=C4=9B=C5=BEn=C3=ADm=20m=C3=ADst=C4=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mo/web/org.py | 33 +++++++++++++++++++++++++++++---- mo/web/templates/org_index.html | 8 ++++++++ static/mo.css | 2 +- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/mo/web/org.py b/mo/web/org.py index 1fae1cc0..dbf1ebcc 100644 --- a/mo/web/org.py +++ b/mo/web/org.py @@ -1,6 +1,6 @@ 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,9 +136,13 @@ 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) - rps_for.append(rp) + + if not o.dozor_place: + rps_for.append(rp) if rcs_for: rcss = (sess.query(db.RegionContestStat) diff --git a/mo/web/templates/org_index.html b/mo/web/templates/org_index.html index f6e3b3d7..20d47d40 100644 --- a/mo/web/templates/org_index.html +++ b/mo/web/templates/org_index.html @@ -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 %} diff --git a/static/mo.css b/static/mo.css index e8394dfb..daebb4b0 100644 --- a/static/mo.css +++ b/static/mo.css @@ -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; } -- GitLab