Skip to content
Snippets Groups Projects
Commit 128b90af authored by Martin Mareš's avatar Martin Mareš Committed by Jiří Kalvoda
Browse files

Přehled soutěží na hlavní orgovské stránce

parent 2fa86ddd
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !82. Comments created here will be created in the context of that merge request.
from flask import render_template, redirect, url_for, request, flash from flask import render_template, redirect, url_for, request, flash, g
from sqlalchemy.orm import aliased from sqlalchemy import and_, or_
from sqlalchemy.orm import aliased, joinedload
from typing import List, Set, Dict
import mo.db as db import mo.db as db
from mo.web.jinja import user_url import mo.rights
import mo.users import mo.users
from mo.web.table import Table, Row, Column
from mo.web import app from mo.web import app
from mo.web.jinja import user_url
from mo.web.table import Table, Row, Column
@app.route('/org/') @app.route('/org/')
...@@ -28,7 +31,37 @@ def org_index(): ...@@ -28,7 +31,37 @@ def org_index():
except ValueError: except ValueError:
flash('ID uživatele musí být číslo', 'danger') flash('ID uživatele musí být číslo', 'danger')
return render_template('org_index.html') sess = db.get_session()
ctr = (sess.query(db.Contest, db.UserRole)
.select_from(db.UserRole, db.Round, db.Contest)
.filter(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),
db.Round.year == mo.current_year,
db.Contest.round_id == db.Round.round_id,
db.Contest.place_id == db.UserRole.place_id))
.options(joinedload(db.Contest.place))
.order_by(db.Round.level, db.Round.category, db.Round.seq, db.Round.part,
db.Contest.place_id, db.Contest.contest_id)
.all())
# Pokud máme pro jednu soutěž více rolí, zkombinujeme je
contests: List[db.Contest] = []
contest_role_sets: Dict[db.Contest, Set[db.RoleType]] = {}
for ct, ur in ctr:
if len(contests) == 0 or contests[-1] != ct:
contests.append(ct)
contest_role_sets[ct.contest_id] = set()
contest_role_sets[ct.contest_id].add(ur.role)
# Role pro každou soutěž setřídíme podle důležitosti
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])
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,6 +2,39 @@ ...@@ -2,6 +2,39 @@
{% block title %}Organizátorské rozhraní{% endblock %} {% block title %}Organizátorské rozhraní{% endblock %}
{% block body %} {% block body %}
{% if contests %}
<h3>Moje soutěže</h3>
<table class="table table-bordered table-condensed greyhead">
{% set curr = namespace(level=-1) %}
{% for c in contests %}
{% if curr.level != c.round.level %}
<thead><tr>
<th>ID
<th>Kategorie
<th>Kolo
<th>{{ c.round.get_level().name|capitalize }}
<th>Stav
<th>Moje role
<th>Odkazy
</thead>
{% set curr.level = c.round.level %}
{% endif %}
<tr>
<td><a href='{{ url_for('org_contest', id=c.contest_id) }}'>{{ c.round.round_code() }}</a>
<td class="text-center"><b>{{ c.round.category }}</b>
<td>{{ c.round.name }}
<td>{{ c.place.name }}
<td class="rstate-{{c.state.name}}">{{ c.state.friendly_name() }}
<td>{% for r in contest_roles[c.contest_id] %}{{ role_type_names[r] }}{% if not loop.last %}<br>{% endif %}{% endfor %}
<td>
<a class="btn btn-xs btn-primary" href='{{ url_for('org_contest', id=c.contest_id) }}'>Detail</a>
{% endfor %}
</table>
{% endif %}
<h3>Různé</h3> <h3>Různé</h3>
<ul> <ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment