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

org_index: Tabulka Moje soutěže na úvodní stránce

parent c47a0c4b
No related branches found
No related tags found
1 merge request!65Tabulka Moje soutěže
from flask import render_template, redirect, url_for, request, flash
from sqlalchemy.orm import aliased
from flask import g, render_template, redirect, url_for, request, flash
from sqlalchemy.orm import aliased, joinedload
import mo.db as db
from mo.rights import Right, roles_by_type
from mo.web.jinja import user_url
import mo.users
from mo.web.table import Table, Row, Column
......@@ -28,7 +29,32 @@ def org_index():
except ValueError:
flash('ID uživatele musí být číslo', 'danger')
return render_template('org_index.html')
sess = db.get_session()
roles = (sess.query(db.UserRole)
.filter_by(user_id=g.user.user_id)
.options(joinedload(db.UserRole.place))
.all())
contests = []
for role in roles:
q = (sess.query(db.Contest, db.UserRole.role, db.Round)
.select_from(db.Contest)
.filter_by(place_id=role.place_id)
.join(db.UserRole, db.UserRole.user_role_id == role.user_role_id)
.join(db.Round))
if role.year:
q = q.filter(db.Round.year == role.year)
if role.category:
q = q.filter(db.Round.category == role.category)
if role.seq:
q = q.filter(db.Round.seq == role.seq)
contests += q.options(joinedload(db.Contest.place)).all()
contests.sort(key=lambda r: (r[2].year, r[2].category, r[2].seq, r[2].part))
return render_template('org_index.html', contests=contests, Right=Right,
role_names=db.role_type_names, gatekeeper=g.gatekeeper)
school_export_columns = (
......
......@@ -2,6 +2,58 @@
{% block title %}Organizátorské rozhraní{% endblock %}
{% block body %}
{% if contests %}
<h3>Moje soutěže</h3>
<table class="table table-bordered">
<thead><tr>
<th>Kategorie
<th>Kolo
<th>Stav
<th>Zadání
<th>Moje role
<th>Odkazy
</thead>
{% for c,role,r in contests %}
{% set rr = gatekeeper.rights_for_contest(c) %}
{% if c.state == RoundState.preparing %}
<tr class="warning">
{% elif c.state == RoundState.running %}
<tr class="success">
{% elif c.state == RoundState.grading %}
<tr class="info">
{% else %}
<tr>
{% endif %}
<td class="text-center" style="font-size: 1.2em"><b>{{ r.category }}</b>
<td>{{ r.name }} {{ c.place.name_locativ() if c.place.level > 0 else '' }}
<td>{{ c.state.friendly_name() }}
<td>
{% if rr.can_view_statement() %}
<a href='{{ url_for('org_task_statement', id=r.round_id) }}'>stáhnout</a>
{% else %}
{{ rr.cannot_view_statement_reason() }}
{% endif %}
<td>{{ role_names[role] }}
<td>
<a class="btn btn-xs btn-primary" href='{{ url_for('org_contest', id=c.contest_id) }}'>Detail</a>
<a class="btn btn-xs btn-default" href='{{ url_for('org_contest_list', id=c.contest_id) }}'>Účastníci</a>
{% if rr.can_view_submits() and c.state != RoundState.preparing %}
<a class="btn btn-xs btn-success" href='{{ url_for('org_contest_solutions', id=c.contest_id) }}'>Odevzdaná řešení</a>
{% endif %}
{% if (c.state == RoundState.grading and rr.can_view_submits()) or c.state == RoundState.closed %}
<a class="btn btn-xs btn-warning" href='{{ url_for('org_score', contest_id=c.contest_id) }}'>Výsledky</a>
{% endif %}
{% if rr.have_right(Right.manage_contest) and c.state != RoundState.closed %}
<a class="btn btn-xs btn-primary" href='{{ url_for('org_contest_add_user', id=c.contest_id) }}'>+ Přidat účastníka</a>
<a class="btn btn-xs btn-default" href='{{ url_for('org_contest_import', id=c.contest_id) }}'>Import</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endif %}
<h3>Různé</h3>
<ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment