diff --git a/bin/create-contests b/bin/create-contests index d7f6e2e912c7c423b645ddf8c4900744803f9afb..81c65c67bab373d4313971531abdfa5efe35f343 100755 --- a/bin/create-contests +++ b/bin/create-contests @@ -48,17 +48,20 @@ else: assert regions, "Neexistují žádná místa dané úrovně" for r in regions: - print(f"Zakládám {round.round_code()} pro místo {r.name}") - if not args.dry_run: - c = db.Contest(round=round, place=r, state=state) - - sess.add(c) - sess.flush() - c.master = c - - mo.util.log(db.LogType.contest, c.contest_id, { - 'action': 'created', - }) + if sess.query(db.Contest).filter_by(round=round, place=r).first(): + print(f"{round.round_code()} pro místo {r.name}: již existuje") + else: + print(f"{round.round_code()} pro místo {r.name}: zakládám") + if not args.dry_run: + c = db.Contest(round=round, place=r, state=state) + + sess.add(c) + sess.flush() + c.master = c + + mo.util.log(db.LogType.contest, c.contest_id, { + 'action': 'created', + }) if not args.dry_run: sess.commit()