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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
e66a4dbf
Commit
e66a4dbf
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Job pro stahování řešení
Dostává množinu papírů, které má zazipovat.
parent
e5428c5c
No related branches found
No related tags found
2 merge requests
!14
Asynchronní joby
,
!9
WIP: Zárodek uživatelské části webu a submitování
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mo/jobs/submit.py
+59
-5
59 additions, 5 deletions
mo/jobs/submit.py
with
59 additions
and
5 deletions
mo/jobs/submit.py
+
59
−
5
View file @
e66a4dbf
# Implementace jobů pracujících se submity
from
mo.util
import
logger
import
os
from
sqlalchemy.orm
import
joinedload
from
tempfile
import
NamedTemporaryFile
from
typing
import
List
import
unicodedata
import
werkzeug.utils
import
zipfile
from
mo.util
import
logger
,
data_dir
import
mo.db
as
db
from
mo.jobs
import
TheJob
,
job_handler
def
schedule_download_submits
(
paper_ids
:
List
[
int
],
description
:
str
,
for_user
:
db
.
User
):
tj
=
TheJob
()
job
=
tj
.
create
(
db
.
JobType
.
download_submits
,
for_user
)
job
.
description
=
description
job
.
in_json
=
{
'
papers
'
:
paper_ids
}
tj
.
submit
()
@job_handler
(
db
.
JobType
.
download_submits
)
def
handle_download_submits
(
tj
:
TheJob
):
logger
.
debug
(
'
Entering download_submits
'
)
pass
"""
Zazipuje zadané papíry.
Vstupní JSON:
{
'
papers
'
: [ seznam paper_id ke stažení ] }
Výstupní JSON:
null
"""
job
=
tj
.
job
assert
job
.
in_json
is
not
None
# FIXME: Typování JSONu...
ids
=
job
.
in_json
[
'
papers
'
]
sess
=
db
.
get_session
()
papers
=
(
sess
.
query
(
db
.
Paper
)
.
filter
(
db
.
Paper
.
paper_id
.
in_
(
ids
))
.
options
(
joinedload
(
db
.
Paper
.
for_user_obj
),
joinedload
(
db
.
Paper
.
task
))
.
all
())
temp_file
=
NamedTemporaryFile
(
suffix
=
'
.zip
'
,
dir
=
data_dir
(
'
tmp
'
),
mode
=
'
w+b
'
)
logger
.
debug
(
'
Job: Vytvářím archiv %s
'
,
temp_file
.
name
)
# FIXME: Setřídit soubory
cnt
=
0
with
zipfile
.
ZipFile
(
temp_file
,
mode
=
'
w
'
)
as
zip
:
for
p
in
papers
:
cnt
+=
1
full_name
=
p
.
for_user_obj
.
full_name
()
ascii_name
=
(
unicodedata
.
normalize
(
'
NFD
'
,
full_name
)
.
encode
(
'
ascii
'
,
'
ignore
'
)
.
decode
(
'
utf-8
'
))
fn
=
f
'
{
p
.
task
.
code
}
_
{
cnt
:
04
d
}
_
{
p
.
for_user
}
_
{
p
.
paper_id
}
_
{
ascii_name
}
.pdf
'
fn
=
werkzeug
.
utils
.
secure_filename
(
fn
)
logger
.
debug
(
'
Job: Přidávám %s
'
,
fn
)
zip
.
write
(
filename
=
os
.
path
.
join
(
data_dir
(
'
submits
'
),
p
.
file_name
),
arcname
=
fn
)
job
.
out_file
=
tj
.
attach_file
(
temp_file
.
name
,
'
.zip
'
)
temp_file
.
close
()
@job_handler
(
db
.
JobType
.
upload_feedback
)
def
handle_upload_feedback
(
tj
:
TheJob
):
logger
.
debug
(
'
Entering upload_feedback
'
)
pass
raise
NotImplementedError
()
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