From ecadfb96d1574e699c9e57e4b5dc3b2d8b41bdb1 Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Tue, 4 Jan 2022 13:03:55 +0100 Subject: [PATCH] =?UTF-8?q?create-contests:=20P=C5=99eskakuje=20ji=C5=BE?= =?UTF-8?q?=20existuj=C3=ADc=C3=AD=20sout=C4=9B=C5=BEe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/create-contests | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/bin/create-contests b/bin/create-contests index d7f6e2e9..81c65c67 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() -- GitLab