Skip to content
Snippets Groups Projects
Commit bd8d30f6 authored by Jiří Setnička's avatar Jiří Setnička
Browse files

Dělená kola: vytváření soutěží vždy v hlavním kole

parent 85963701
Branches
No related tags found
1 merge request!48Dělená kola napotřetí
......@@ -102,16 +102,17 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
flash(f'Místo s kódem {form.place_code.data} neexistuje', 'danger')
return False
if place.level != round.level:
flash(f'{place.type_name().title()} {place.name} není {db.place_level_names[round.level]}', 'danger')
return False
# if place.level != round.level:
# flash(f'{place.type_name().title()} {place.name} není {db.place_level_names[round.level]}', 'danger')
# return False
sess = db.get_session()
if sess.query(db.Contest).filter_by(round=round, place=place).one_or_none():
flash(f'Pro {place.type_name()} {place.name} už toto kolo existuje', 'danger')
return False
contest = db.Contest(round=round, place=place)
# Soutěž vytvoříme vždy v hlavním kole
contest = db.Contest(round=round.master, place=place)
rr = g.gatekeeper.rights_for_contest(contest)
if not rr.have_right(Right.add_contest):
flash('Vaše role nedovoluje vytvořit soutěž v oblasti {place.type_name()} {place.name}', 'danger')
......@@ -119,6 +120,9 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
sess.add(contest)
sess.flush()
contest.master_contest_id = contest.contest_id
sess.add(contest)
sess.flush()
mo.util.log(
type=db.LogType.contest,
......@@ -126,8 +130,26 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
details={'action': 'add', 'contest': db.row2dict(contest)},
)
app.logger.info(f"Soutěž #{contest.contest_id} založena: {db.row2dict(contest)}")
sess.commit()
# Přidání soutěže do podkol ve skupině
subrounds = round.master.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,
)
sess.add(subcontest)
sess.flush()
mo.util.log(
type=db.LogType.contest,
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'Soutěž v oblasti {place.type_name()} {place.name} založena', 'success')
return True
......
......@@ -17,7 +17,7 @@
<td><a href='{{ url_for('org_round', id=r.round_id) }}'>{{ r.round_code() }}</a>
<td>{{ r.year }}
<td>{{ r.category }}
<td>{{ r.seq }}
<td>{{ r.seq }}{{ r.part_code() }}
<td>{{ level_names[r.level] }}
<td>{{ r.name }}
<td class='rstate-{{r.state.name}}'>{{ r.state.friendly_name() }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment