Skip to content
Snippets Groups Projects
Commit 98a37587 authored by Martin Mareš's avatar Martin Mareš
Browse files

fixup! fixup! fixup! fixup! fixup! Diplomy/UI: Přehled ocenění studentů pro školní garanty

parent 7fe6133a
No related branches found
No related tags found
No related merge requests found
......@@ -291,35 +291,29 @@ def org_school_results_certs(school_id: int, ct_id: int, cert_type: str, filenam
if filename != ctype.file_name(plural=True) + '.pdf':
raise werkzeug.exceptions.NotFound()
certs_and_files = (sess.query(db.User, db.Certificate, db.CertFile)
cfile = sess.query(db.CertFile).filter_by(cert_set_id=ct_id, type=ctype, approved=True).one_or_none()
if cfile is None:
raise werkzeug.exceptions.NotFound()
users_and_certs = (sess.query(db.User, db.Certificate)
.select_from(db.Certificate)
.join(db.Certificate.cert_file)
.join(db.Participant, and_(db.Participant.user_id == db.Certificate.user_id,
db.Participant.year == config.CURRENT_YEAR,
db.Participant.school == school_id))
.join(db.Certificate.user)
.filter(db.Certificate.cert_set_id == ct_id,
db.Certificate.type == ctype,
db.CertFile.approved)
db.Certificate.type == ctype)
.all())
certs_and_files.sort(key=lambda x: x[0].sort_key())
source_pdfs = {}
dst = None
users_and_certs.sort(key=lambda x: x[0].sort_key())
try:
try:
for _, _, cfile in certs_and_files:
if cfile not in source_pdfs:
file = os.path.join(mo.util.data_dir('certs'), cfile.pdf_file)
if not os.path.isfile(file):
app.logger.error(f'Certifikát {file} je v DB, ale soubor neexistuje')
raise werkzeug.exceptions.NotFound()
source_pdfs[cfile] = pikepdf.open(file, attempt_recovery=False)
dst = pikepdf.new()
for _, cert, cfile in certs_and_files:
src = source_pdfs[cfile]
with pikepdf.open(file, attempt_recovery=False) as src:
with pikepdf.new() as dst:
for _, cert in users_and_certs:
dst.pages.append(src.pages[cert.page_number - 1])
dst.docinfo['/Title'] = f'Matematická Olympiáda – {ctype.friendly_name(plural=True)}'
dst.docinfo['/Creator'] = 'Odevzdávací Systém Matematické Olympiády'
......@@ -330,13 +324,6 @@ def org_school_results_certs(school_id: int, ct_id: int, cert_type: str, filenam
app.logger.error(f'Chyba při zpracování PDF certifikátů: {e}')
raise werkzeug.exceptions.InternalServerError()
except RuntimeError:
for pdf in source_pdfs.values():
pdf.close()
if dst is not None:
dst.close()
raise
return send_file(open(tmp_file.name, 'rb'), mimetype='application/pdf')
......@@ -371,9 +358,10 @@ def org_school_results(school_id: int):
contests = (sess.query(db.Contest)
.filter(db.Contest.contest_id.in_(contest_ids))
.options(joinedload(db.Contest.round))
.options(joinedload(db.Contest.round),
joinedload(db.Contest.place))
.all())
contests.sort(key=lambda c: (c.round.category, c.round.seq)) # part nepotřebujeme, vše jsou hlavní soutěže
contests.sort(key=lambda c: (c.round.category, c.round.seq, locale.strxfrm(c.place.name))) # part nepotřebujeme, vše jsou hlavní soutěže
cert_counts = (sess.query(db.CertFile.cert_set_id, db.CertFile.type, func.count(db.Certificate.user_id))
.select_from(db.Certificate)
......
......@@ -25,6 +25,9 @@ Ocenění studentů {{ place.name }}
<tr>
<td>{{ c.round.category }}
<td>{% if c.round.round_type == RoundType.other %}{{ c.round.name }}{% else %}{{ c.round.round_type.friendly_name() }}{% endif %}
{% if c.round.level < 4 %}
({{ c.place.name }})
{% endif %}
<td class=ar>{{ num_pants_by_cid[c.contest_id] }}
{% if c.state == RoundState.closed %}
<td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment