diff --git a/mo/jobs/certs.py b/mo/jobs/certs.py index a6d90a7329f3b1c0996c5a8b709ebf108cdcc7fe..0900537eebec47115ae73cc2921a12d689aaf2a2 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