diff --git a/mo/web/org.py b/mo/web/org.py index 2aa1f4cf022ff4c3ed016813b76f5033079bfff1..142c741fc7a209d0155d2e2b6d2f9a7dd0e27374 100644 --- a/mo/web/org.py +++ b/mo/web/org.py @@ -1,7 +1,8 @@ -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 = ( diff --git a/mo/web/templates/org_index.html b/mo/web/templates/org_index.html index 3244560a7a35b1ed49cf594848f2e3e7721e51e9..b631bcb29c1fe6c74565b3154791b7b09f3c01e9 100644 --- a/mo/web/templates/org_index.html +++ b/mo/web/templates/org_index.html @@ -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>