Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Réouven ASSOULY
zesje
Commits
7a893db1
Commit
7a893db1
authored
7 years ago
by
Joseph Weston
Browse files
Options
Downloads
Patches
Plain Diff
add a PDF model and implement getting/setting to DB and saving PDF
parent
91d25c59
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
zesje/__init__.py
+2
-2
2 additions, 2 deletions
zesje/__init__.py
zesje/models.py
+8
-0
8 additions, 0 deletions
zesje/models.py
zesje/resources/pdfs.py
+22
-10
22 additions, 10 deletions
zesje/resources/pdfs.py
with
32 additions
and
12 deletions
zesje/__init__.py
+
2
−
2
View file @
7a893db1
...
...
@@ -30,8 +30,8 @@ def setup():
auth
.
init_app
(
app
)
data_dir
=
app
.
config
[
'
DATA_DIRECTORY
'
]
if
not
os
.
path
.
exists
(
data_dir
):
os
.
makedirs
(
data_dir
)
os
.
makedirs
(
data_dir
,
exist_ok
=
True
)
os
.
makedirs
(
os
.
path
.
join
(
data_dir
,
'
pdfs
'
),
exist_ok
=
True
)
db
.
bind
(
'
sqlite
'
,
f
"
{
app
.
config
[
'
DATA_DIRECTORY
'
]
}
/course.sqlite
"
,
create_db
=
True
)
db
.
generate_mapping
(
create_tables
=
True
)
...
...
This diff is collapsed.
Click to expand it.
zesje/models.py
+
8
−
0
View file @
7a893db1
...
...
@@ -28,6 +28,7 @@ class Exam(db.Entity):
yaml_path
=
Required
(
str
)
submissions
=
Set
(
'
Submission
'
)
problems
=
Set
(
'
Problem
'
)
pdfs
=
Set
(
'
PDF
'
)
class
Submission
(
db
.
Entity
):
...
...
@@ -79,3 +80,10 @@ class Solution(db.Entity):
feedback
=
Set
(
FeedbackOption
)
remarks
=
Optional
(
str
)
class
PDF
(
db
.
Entity
):
"""
Metadata on uploaded PDFs
"""
exam
=
Required
(
Exam
)
name
=
Required
(
str
)
status
=
Required
(
str
)
message
=
Optional
(
str
)
This diff is collapsed.
Click to expand it.
zesje/resources/pdfs.py
+
22
−
10
View file @
7a893db1
...
...
@@ -6,7 +6,7 @@ from werkzeug.datastructures import FileStorage
from
pony
import
orm
from
..models
import
db
,
Exam
from
..models
import
db
,
Exam
,
PDF
class
Pdfs
(
Resource
):
...
...
@@ -28,18 +28,18 @@ class Pdfs(Resource):
"""
return
[
{
'
id
'
:
1
,
'
name
'
:
'
hello.pdf
'
,
'
status
'
:
'
processing
'
,
'
message
'
:
'
extracting im
age
s
'
,
'
id
'
:
pdf
.
id
,
'
name
'
:
pdf
.
name
,
'
status
'
:
pdf
.
status
,
'
message
'
:
pdf
.
mess
age
,
}
for
pdf
in
PDF
.
select
(
lambda
pdf
:
pdf
.
exam
.
id
==
exam_id
)
]
post_parser
=
reqparse
.
RequestParser
()
post_parser
.
add_argument
(
'
pdf
'
,
type
=
FileStorage
,
required
=
True
,
location
=
'
files
'
)
@orm.db_session
def
post
(
self
,
exam_id
):
"""
Upload a PDF
...
...
@@ -56,9 +56,21 @@ class Pdfs(Resource):
message : str
"""
args
=
self
.
post_parser
.
parse_args
()
if
args
[
'
pdf
'
].
mimetype
!=
'
application/pdf
'
:
return
dict
(
message
=
'
Uploaded file is not a PDF
'
),
400
pdf_path
=
os
.
path
.
join
(
app
.
config
[
'
DATA_DIRECTORY
'
],
'
pdfs
'
,
f
'
{
pdf
.
id
}
.pdf
'
)
with
orm
.
db_session
:
pdf
=
PDF
(
exam
=
Exam
[
exam_id
],
name
=
args
[
'
pdf
'
].
filename
,
status
=
'
processing
'
,
message
=
'
importing PDF
'
)
# if we fail to save the PDF then we rollback the DB transaction
args
[
'
pdf
'
].
save
(
pdf_path
)
# TODO fire off subprocess
return
{
'
id
'
:
1
,
'
name
'
:
'
hello.pdf
'
,
'
status
'
:
'
processing
'
,
'
message
'
:
'
going
'
,
'
id
'
:
pdf
.
id
,
'
name
'
:
pdf
.
name
,
'
status
'
:
pdf
.
status
,
'
message
'
:
pdf
.
message
}
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