Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
98a37587
Commit
98a37587
authored
5 months ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mo/web/org_certs.py
+26
-38
26 additions, 38 deletions
mo/web/org_certs.py
mo/web/templates/org_school_results.html
+3
-0
3 additions, 0 deletions
mo/web/templates/org_school_results.html
with
29 additions
and
38 deletions
mo/web/org_certs.py
+
26
−
38
View file @
98a37587
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
mo/web/templates/org_school_results.html
+
3
−
0
View file @
98a37587
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment