From 805571f251ec9856deee39a05f8bbed4f0e21c21 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Sun, 9 Feb 2025 21:32:41 +0100
Subject: [PATCH] =?UTF-8?q?Diplomy/sazba:=20P=C5=99ed=C3=A1v=C3=A1me=20i?=
 =?UTF-8?q?=20ID=20v=C3=BDsledkov=C3=A9=20listiny,=20podle=20kter=C3=A9=20?=
 =?UTF-8?q?vyd=C3=A1vat?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mo/jobs/certs.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/mo/jobs/certs.py b/mo/jobs/certs.py
index a6d90a73..0900537e 100644
--- a/mo/jobs/certs.py
+++ b/mo/jobs/certs.py
@@ -19,7 +19,7 @@ import mo.util_format
 from mo.util_tex import tex_arg, tex_key, run_tex, format_hacks, QREncoder
 
 
-def schedule_create_certs(contest: db.Contest, for_user: db.User) -> int:
+def schedule_create_certs(contest: db.Contest, scoretable_id: Optional[int], for_user: db.User) -> int:
     place = contest.place
 
     the_job = TheJob()
@@ -27,6 +27,7 @@ def schedule_create_certs(contest: db.Contest, for_user: db.User) -> int:
     job.description = f'Diplomy {contest.round.round_code()} {place.name_locative()}'
     job.in_json = {
         'contest_id': contest.contest_id,
+        'scoretable_id': scoretable_id,
     }
     the_job.submit()
     assert the_job.job_id is not None
@@ -141,18 +142,27 @@ class CertMaker:
         walker = Walker(self.job.in_json)
         with walker.enter_object() as root:
             self.contest_id = root['contest_id'].as_int()
+            if root['scoretable_id'].is_null():
+                scoretable_id = None
+            else:
+                scoretable_id = root['scoretable_id'].as_int()
 
         sess = db.get_session()
         self.contest = (sess.query(db.Contest)
                         .options(joinedload(db.Contest.round))
                         .options(joinedload(db.Contest.place))
-                        .options(joinedload(db.Contest.scoretable))
                         .get(self.contest_id)
                        )
         assert self.contest is not None
         self.round = self.contest.round
         self.place = self.contest.place
-        self.scoretable = self.contest.scoretable
+        logger.info(f'{self.the_job.log_prefix} Vytvářím certifikáty pro soutěž #{self.contest.contest_id} s výsledkovou listinou #{scoretable_id}')
+
+        if scoretable_id is not None:
+            self.scoretable = sess.query(db.ScoreTable).get(scoretable_id)
+            assert self.scoretable is not None
+        else:
+            self.scoretable = None
 
         self.cset = sess.query(db.CertSet).get(self.contest_id)
         assert self.cset is not None
-- 
GitLab