Skip to content
Snippets Groups Projects

Sazba diplomů

Merged Martin Mareš requested to merge diplomy into devel
2 files
+ 52
20
Compare changes
  • Side-by-side
  • Inline

Files

+ 35
13
# Implementace jobů na práci s diplomy
from dataclasses import dataclass, asdict
from dataclasses import dataclass, asdict, fields
from enum import auto
import os
from sqlalchemy import and_
@@ -16,7 +16,7 @@ from mo.jobs import TheJob, job_handler
import mo.util
from mo.util import logger
import mo.util_format
from mo.util_tex import tex_arg, run_tex, format_hacks, QREncoder
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:
@@ -58,6 +58,14 @@ class DesignParams:
issue_place: str = ""
issue_date: str = ""
background_type: BackgroundType = BackgroundType.standard
space1: float = -1 # kladná čísla jsou mm, záporná filly
space2: float = -1
space3: float = -1
space4: float = -1
space5: float = 15
space6: float = 0
SPACE_PARAMS = [f'space{i}' for i in range(1, 7)]
logo_visible: bool = True
def to_json(self) -> Any:
json = asdict(self)
@@ -75,6 +83,9 @@ class DesignParams:
p.issue_place = w['issue_place'].as_str(p.issue_place)
p.issue_date = w['issue_date'].as_str(p.issue_date)
p.background_type = w['background_type'].as_enum(BackgroundType, p.background_type)
for key in DesignParams.SPACE_PARAMS:
setattr(p, key, w[key].as_float(getattr(p, key)))
p.logo_visible = w['logo_visible'].as_bool(p.logo_visible)
return p
@@ -133,11 +144,11 @@ class CertMaker:
self.certs = []
self.out_files = {}
self.qr_encoder = QREncoder(f'{self.job.dir_path()}/qr')
self.certs_dir = mo.util.data_dir('certs')
self.out_dir = os.path.join(self.round.round_code_short(), str(self.contest.contest_id))
self.out_dir = self.cset.dir_path()
self.job_dir = self.job.dir_path()
self.qr_encoder = QREncoder(os.path.join(self.job_dir, 'qr'))
def plan(self) -> None:
sess = db.get_session()
@@ -188,10 +199,17 @@ class CertMaker:
add_cert(db.CertType.honorary_mention, 'za úplné vyřešení úlohy', user.sort_key())
def prepare_files(self) -> None:
if self.cset.background_file:
if self.design_params.background_type == BackgroundType.custom:
b = os.path.join(self.certs_dir, self.cset.background_file)
elif self.design_params.background_type == BackgroundType.standard:
b = os.path.join(mo.util.part_path('tex'), 'cert-background.pdf')
else:
b = None
if b:
background = os.path.join(self.job_dir, 'background.pdf')
mo.util.unlink_if_exists(background)
os.link(os.path.join(self.certs_dir, self.cset.background_file), background)
os.link(b, background)
def make_certs(self, cert_type: db.CertType) -> None:
certs = [cert for cert in self.certs if cert.type == cert_type]
@@ -218,14 +236,18 @@ class CertMaker:
ga = {
'kolo': db.round_type_names_local[self.round.round_type],
'kat': self.round.category,
'signerAname': dparams.signer1_name,
'signerAtitle': dparams.signer1_title,
'signerBname': dparams.signer2_name,
'signerBtitle': dparams.signer2_title,
'issueplace': dparams.issue_place,
'issuedate': dparams.issue_date,
'background': "background.pdf" if self.cset.background_file else "",
'background': "background.pdf" if dparams.background_type != BackgroundType.blank else ""
}
for field in fields(DesignParams):
key = field.name
val = getattr(dparams, key)
if field.type is bool:
tval = "true" if val else ""
elif field.type is float:
tval = f'{val}mm' if val >= 0 else f'0 pt plus {-val}fill'
else:
tval = str(val)
ga[tex_key(key)] = tval
if self.round.round_type in (db.RoundType.okresni, db.RoundType.krajske):
ga['oblast'] = self.place.name
attrs(ga)
Loading