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

Při uzavírání soutěží zobrazovat jejich počty

parent b5e4525c
Branches
No related tags found
No related merge requests found
......@@ -769,6 +769,11 @@ def org_close_contests(round_id: int, hier_id: Optional[int] = None):
flash('Stav kola neumožňuje ukončovat jednotlivé soutěže', 'danger')
return redirect(ctx.url_for('org_round'))
contests_q = sess.query(db.Contest).filter_by(round=ctx.round)
if ctx.hier_place is not None:
contests_q = db.filter_place_nth_parent(contests_q, db.Contest.place_id, ctx.round.level - ctx.hier_place.level, ctx.hier_place.place_id)
contests_nonclosed_q = contests_q.filter(db.Contest.state != db.RoundState.closed)
form = CloseContestsForm()
errors = mo.contests.check_contest_state(round=ctx.round, hier_place=ctx.hier_place, state=db.RoundState.closed)
......@@ -776,11 +781,7 @@ def org_close_contests(round_id: int, hier_id: Optional[int] = None):
if form.back.data:
return redirect(ctx.url_for('org_round'))
if form.submit.data and not errors or form.force_submit.data:
contests_q = sess.query(db.Contest).filter_by(round=ctx.round)
if ctx.hier_place is not None:
contests_q = db.filter_place_nth_parent(contests_q, db.Contest.place_id, ctx.round.level - ctx.hier_place.level, ctx.hier_place.place_id)
contests = contests_q.filter(db.Contest.state != db.RoundState.closed).all()
contests = contests_nonclosed_q.all()
for c in contests:
c.state = db.RoundState.closed
changes = db.get_object_changes(c)
......@@ -795,12 +796,20 @@ def org_close_contests(round_id: int, hier_id: Optional[int] = None):
flash(inflect_with_number(len(contests), 'Ukončena %s soutěž.', 'Ukončeny %s soutěže.', 'Ukončeno %s soutěží.'), 'success')
return redirect(ctx.url_for('org_round'))
if not errors:
num_contests = db.get_count(contests_q)
num_nonclosed_contests = db.get_count(contests_nonclosed_q)
if num_nonclosed_contests == 0:
del form.submit
del form.force_submit
elif not errors:
del form.force_submit
return render_template(
'org_close_contests.html',
ctx=ctx,
form=form,
num_contests=num_contests,
num_nonclosed_contests=num_nonclosed_contests,
errors=errors,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment