Skip to content
Snippets Groups Projects
Commit 57c70632 authored by Martin Mareš's avatar Martin Mareš
Browse files

Hierarchie: Organizátorská hlavní stránka

Kromě soutěží odkazuje i na hierarchické stránky kol, pokud jsem
garant vyšší úrovně, než je úroveň kola.
parent 0a189cca
No related branches found
No related tags found
1 merge request!95Reforma orgovského rozhraní ke kolům a soutěžím
from dataclasses import dataclass, field
from flask import render_template, redirect, url_for, request, flash, g from flask import render_template, redirect, url_for, request, flash, g
from sqlalchemy import and_, or_ from sqlalchemy import and_, or_
from sqlalchemy.orm import aliased, joinedload from sqlalchemy.orm import aliased, joinedload
from typing import List, Set, Dict from typing import List, Set, Optional
import mo.config as config import mo.config as config
import mo.db as db import mo.db as db
...@@ -12,6 +13,15 @@ from mo.web.jinja import user_url ...@@ -12,6 +13,15 @@ from mo.web.jinja import user_url
from mo.web.table import Table, Row, Column from mo.web.table import Table, Row, Column
@dataclass
class OrgOverview:
round: db.Round
place: db.Place
contest: Optional[db.Contest]
role_set: Set[db.RoleType] = field(default_factory=set)
role_list: List[db.RoleType] = field(default_factory=list)
@app.route('/org/') @app.route('/org/')
def org_index(): def org_index():
if 'place' in request.args: if 'place' in request.args:
...@@ -33,36 +43,33 @@ def org_index(): ...@@ -33,36 +43,33 @@ def org_index():
flash('ID uživatele musí být číslo', 'danger') flash('ID uživatele musí být číslo', 'danger')
sess = db.get_session() sess = db.get_session()
ctr = (sess.query(db.Contest, db.UserRole) rcu = (sess.query(db.Round, db.Contest, db.UserRole)
.select_from(db.UserRole, db.Round, db.Contest) .select_from(db.UserRole)
.filter(and_(db.UserRole.user_id == g.user.user_id, .join(db.Place)
.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.category == None, db.UserRole.category == db.Round.category),
or_(db.UserRole.year == None, db.UserRole.year == db.Round.year), or_(db.UserRole.year == None, db.UserRole.year == db.Round.year),
or_(db.UserRole.seq == None, db.UserRole.seq == db.Round.seq), or_(db.UserRole.seq == None, db.UserRole.seq == db.Round.seq),
db.Round.year == config.CURRENT_YEAR, db.Place.level <= db.Round.level))
db.Contest.round_id == db.Round.round_id, .outerjoin(db.Contest, and_(db.Contest.round_id == db.Round.round_id, db.Contest.place_id == db.UserRole.place_id))
db.Contest.place_id == db.UserRole.place_id)) .filter(db.Round.year == config.CURRENT_YEAR)
.options(joinedload(db.Contest.place)) .options(joinedload(db.UserRole.place))
.order_by(db.Round.level, db.Round.category, db.Round.seq, db.Round.part, .order_by(db.Round.level, db.Round.category, db.Round.seq, db.Round.part,
db.Contest.place_id, db.Contest.contest_id) db.Contest.place_id, db.Contest.contest_id)
.all()) .all())
# Pokud máme pro jednu soutěž více rolí, zkombinujeme je overview: List[OrgOverview] = []
contests: List[db.Contest] = [] for r, ct, ur in rcu:
contest_role_sets: Dict[db.Contest, Set[db.RoleType]] = {} o = overview[-1] if overview else None
for ct, ur in ctr: if not (o and o.round == r and o.place == ur.place):
if len(contests) == 0 or contests[-1] != ct: o = OrgOverview(round=r, place=ur.place, contest=ct)
contests.append(ct) overview.append(o)
contest_role_sets[ct.contest_id] = set() o.role_set.add(ur.role)
contest_role_sets[ct.contest_id].add(ur.role)
for o in overview:
# Role pro každou soutěž setřídíme podle důležitosti o.role_list = sorted(o.role_set, key=lambda r: mo.rights.role_order_by_type[r])
contest_roles: Dict[db.Contest, List[db.RoleType]] = {
ct_id: sorted(list(contest_role_sets[ct_id]), key=lambda r: mo.rights.role_order_by_type[r]) return render_template('org_index.html', overview=overview, role_type_names=db.role_type_names)
for ct_id in contest_role_sets.keys()
}
return render_template('org_index.html', contests=contests, contest_roles=contest_roles, role_type_names=db.role_type_names)
school_export_columns = ( school_export_columns = (
......
...@@ -2,34 +2,46 @@ ...@@ -2,34 +2,46 @@
{% block title %}Organizátorské rozhraní{% endblock %} {% block title %}Organizátorské rozhraní{% endblock %}
{% block body %} {% block body %}
{% if contests %} {% if overview %}
<h3>Moje soutěže</h3> <h3>Moje soutěže</h3>
<table class="table table-bordered table-condensed greyhead"> <table class="table table-bordered table-condensed greyhead">
{% set curr = namespace(level=-1) %} {% set curr = namespace(level=-1) %}
{% for c in contests %} {% for o in overview %}
{% if curr.level != c.round.level %} {% if curr.level != o.round.level %}
<thead><tr> <thead><tr>
<th>ID <th>ID
<th>Kategorie <th>Kategorie
<th>Kolo <th>Kolo
<th>{{ c.round.get_level().name|capitalize }} <th>{{ o.round.get_level().name|capitalize }}
<th>Stav <th>Stav
<th>Moje role <th>Moje role
<th>Odkazy <th>Odkazy
</thead> </thead>
{% set curr.level = c.round.level %} {% set curr.level = o.round.level %}
{% endif %}
{% if o.contest %}
{% set detail_url = url_for('org_contest', ct_id=o.contest.contest_id) %}
{% elif o.place.level == 0 %}
{% set detail_url = url_for('org_round', round_id=o.round.round_id) %}
{% else %}
{% set detail_url = url_for('org_round', round_id=o.round.round_id, hier_id=o.place.place_id) %}
{% endif %} {% endif %}
<tr> <tr>
<td><a href='{{ url_for('org_contest', ct_id=c.contest_id) }}'>{{ c.round.round_code() }}</a> <td><a href='{{ detail_url }}'>{{ o.round.round_code() }}</a>
<td class="text-center"><b>{{ c.round.category }}</b> <td class="text-center"><b>{{ o.round.category }}</b>
<td>{{ c.round.name }} <td>{{ o.round.name }}
<td>{{ c.place.name }} {% if o.contest %}
<td class="rstate-{{c.state.name}}">{{ c.state.friendly_name() }} <td>{{ o.place.name }}
<td>{% for r in contest_roles[c.contest_id] %}{{ role_type_names[r] }}{% if not loop.last %}<br>{% endif %}{% endfor %} <td class="rstate-{{o.contest.state.name}}">{{ o.contest.state.friendly_name() }}
{% else %}
<td><i>{{ o.place.name_locative() }}</i>
<td> <td>
<a class="btn btn-xs btn-primary" href='{{ url_for('org_contest', ct_id=c.contest_id) }}'>Detail</a> {% endif %}
<td>{% for r in o.role_list %}{{ role_type_names[r] }}{% if not loop.last %}<br>{% endif %}{% endfor %}
<td><a class="btn btn-xs btn-primary" href='{{ detail_url }}'>Detail</a>
{% endfor %} {% endfor %}
</table> </table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment