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

Registrace: Soutěže s více částmi

parent 9529b3e3
No related branches found
No related tags found
1 merge request!86Registrace
......@@ -152,14 +152,26 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
)
app.logger.info(f"Soutěž #{contest.contest_id} založena: {db.row2dict(contest)}")
# Přidání soutěže do podkol ve skupině
subrounds = round.master.get_group_rounds()
create_subcontests(round.master, contest)
sess.commit()
flash(f'Založena soutěž {place.name_locative()}', 'success')
return True
# XXX: Používá se i v registraci účastníků
def create_subcontests(master_round: db.Round, master_contest: db.Contest):
if master_round.part == 0:
return
sess = db.get_session()
subrounds = master_round.get_group_rounds()
for subround in subrounds:
subcontest = db.Contest(
round_id=subround.round_id,
master_contest_id=contest.contest_id,
place_id=contest.place_id,
state=state,
master_contest_id=master_contest.contest_id,
place_id=master_contest.place_id,
state=master_contest.state,
)
sess.add(subcontest)
sess.flush()
......@@ -169,11 +181,7 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
what=subcontest.contest_id,
details={'action': 'add', 'contest': db.row2dict(subcontest)},
)
app.logger.info(f"Soutěž #{subcontest.contest_id} založena: {db.row2dict(subcontest)}")
sess.commit()
flash(f'Založena soutěž {place.name_locative()}', 'success')
return True
app.logger.info(f"Podsoutěž #{subcontest.contest_id} založena: {db.row2dict(subcontest)}")
@app.route('/org/contest/r/<int:id>/', methods=('GET', 'POST'))
......
......@@ -18,6 +18,7 @@ from mo.util import logger
from mo.util_format import time_and_timedelta
from mo.web import app
import mo.web.fields as mo_fields
import mo.web.org_round
import mo.web.util
......@@ -87,7 +88,7 @@ def user_join_round(round_id):
raise werkzeug.exceptions.NotFound()
if (round.year != mo.current_year
or round.part != 0
or round.part > 1
or round.enroll_mode not in [db.RoundEnrollMode.register, db.RoundEnrollMode.confirm]
or round.state != db.RoundState.running):
flash('Do této kategorie se není možné přihlásit.', 'danger')
......@@ -181,7 +182,7 @@ def join_create_contest(round: db.Round, pant: db.Participant) -> db.Contest:
# XXX: Z rekurzivního dotazu nedostaneme plnohodnotný db.Place, ale jenom named tuple, tak musíme pracovat s ID.
place_id = place.place_id
assert round.part == 0 # U kol s více částmi bude potřeba založit všechny contesty, ale přihlásit jen do primárního
assert round.part <= 1
c = (sess.query(db.Contest)
.filter_by(round=round, place_id=place_id)
.with_for_update()
......@@ -203,6 +204,8 @@ def join_create_contest(round: db.Round, pant: db.Participant) -> db.Contest:
details={'action': 'created', 'reason': 'user-join'},
)
mo.web.org_round.create_subcontests(round, c)
return c
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment