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

Overview: Odkaz na založení soutěže

Zatím vede na špatné místo, další commity doplní správný.
parent 7d63ceec
No related branches found
No related tags found
1 merge request!123Zakládání soutěží z orgovské hlavní stránky
......@@ -25,6 +25,7 @@ class OrgOverview:
contest_states: Set[db.RoundState] = field(default_factory=set)
num_active_pants: int = 0
num_unconfirmed_pants: int = 0
create: bool = False
@app.route('/org/')
......@@ -88,11 +89,11 @@ def org_index():
overview: List[OrgOverview] = []
for r, ct, ur in rcu:
if ct is None and ur.place.level == r.level:
continue
o = overview[-1] if overview else None
if not (o and o.round == r and o.place == ur.place and o.contest == ct):
o = OrgOverview(round=r, place=ur.place, contest=ct)
if ct is None and ur.place.level == r.level:
o.create = True
overview.append(o)
o.role_set.add(ur.role)
......@@ -112,6 +113,8 @@ def get_stats(overview: List[OrgOverview]) -> None:
rcs_for: List[Tuple[int, int]] = []
rps_for: List[Tuple[int, int]] = []
for o in overview:
if o.create:
continue
if o.contest:
o.num_contests = 1
o.contest_states.add(o.contest.state)
......@@ -159,12 +162,40 @@ def filter_overview(overview: List[OrgOverview]) -> List[OrgOverview]:
else:
# Ostatní role (garanti a pozorovatelé) vidí všechny soutěže
want = True
if want and o.create and not want_create_contest(o):
want = False
if want:
out.append(o)
return out
def want_create_contest(o: OrgOverview) -> bool:
# Založení soutěže nabízíme jen tehdy, pokud už kolo běží. V opačném případě sice
# org také může mít právo soutěž založit, ale v tabulce by vznikala
# spousta balastu o budoucích kolech.
if o.round.state not in [db.RoundState.running, db.RoundState.delegate]:
return False
# Pokud je soutěžní místo škola, omezujeme kategorie podle typu školy
if o.place.type == db.PlaceType.school:
cat = o.round.category
if o.place.school.is_zs:
if cat.startswith("Z"):
return True
if o.place.school.is_ss:
if cat in "ABC":
return True
# Okresní a krajská kola jsou vždy OK
if o.place.level in [1, 2]:
return True
return False
school_export_columns = (
Column(key='code', name='kod'),
Column(key='name', name='nazev'),
......
......@@ -22,6 +22,8 @@
{% set curr.category = o.round.category %}
{% endif %}
{% set create = not o.contest and o.place.level == o.round.level %}
{% if o.contest %}
{% if o.place == o.contest.place %}
{% set detail_url = url_for('org_contest', ct_id=o.contest.contest_id) %}
......@@ -44,15 +46,25 @@
{% else %}
<td>{{ o.contest.place.name }} {{ o.place.name_locative() }}
{% endif %}
{% elif create %}
<td>{{ o.place.name }}
{% else %}
<td><i>{{ o.place.name_locative() }}</i>
{% endif %}
<td>{% for s in o.contest_states %}{% if not loop.first %}<br>{% endif %}<span class="rstate-{{s.name}}">{{ s.friendly_name() }}</span>{% endfor %}
{% if create %}
<td>
{% else %}
<td>{% if not o.contest %}{{ o.num_contests }}S / {% endif %}
{{- o.num_active_pants }}U
{%- if o.num_unconfirmed_pants %} / <span class='warning-text'>{{ o.num_unconfirmed_pants }}P</span>{% endif %}
{% endif %}
<td>{% for r in o.role_list %}{{ role_type_names[r] }}{% if not loop.last %}<br>{% endif %}{% endfor %}
{% if create %}
<td><a class="btn btn-xs btn-success" href='{{ detail_url }}'>Založit</a>
{% else %}
<td><a class="btn btn-xs btn-primary" href='{{ detail_url }}'>Detail</a>
{% endif %}
{% endfor %}
</table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment