Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
2470c8df
Commit
2470c8df
authored
2 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Remove redundant code
parent
086fe226
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/corpora/routes.py
+1
-1
1 addition, 1 deletion
app/corpora/routes.py
app/models.py
+20
-60
20 additions, 60 deletions
app/models.py
app/services/routes.py
+4
-4
4 additions, 4 deletions
app/services/routes.py
with
25 additions
and
65 deletions
app/corpora/routes.py
+
1
−
1
View file @
2470c8df
...
@@ -149,7 +149,7 @@ def create_corpus_file(corpus_id):
...
@@ -149,7 +149,7 @@ def create_corpus_file(corpus_id):
mimetype
=
'
application/vrt+xml
'
,
mimetype
=
'
application/vrt+xml
'
,
corpus
=
corpus
corpus
=
corpus
)
)
except
OSError
:
except
(
AttributeError
,
OSError
)
:
abort
(
500
)
abort
(
500
)
corpus
.
status
=
CorpusStatus
.
UNPREPARED
corpus
.
status
=
CorpusStatus
.
UNPREPARED
db
.
session
.
commit
()
db
.
session
.
commit
()
...
...
This diff is collapsed.
Click to expand it.
app/models.py
+
20
−
60
View file @
2470c8df
...
@@ -91,6 +91,26 @@ class FileMixin:
...
@@ -91,6 +91,26 @@ class FileMixin:
),
),
'
mimetype
'
:
self
.
mimetype
'
mimetype
'
:
self
.
mimetype
}
}
@classmethod
def
create
(
cls
,
file_storage
,
**
kwargs
):
filename
=
kwargs
.
pop
(
'
filename
'
,
file_storage
.
filename
)
mimetype
=
kwargs
.
pop
(
'
mimetype
'
,
file_storage
.
mimetype
)
obj
=
cls
(
filename
=
secure_filename
(
filename
),
mimetype
=
mimetype
,
**
kwargs
)
db
.
session
.
add
(
obj
)
db
.
session
.
flush
(
objects
=
[
obj
])
db
.
session
.
refresh
(
obj
)
try
:
file_storage
.
save
(
obj
.
path
)
except
(
AttributeError
,
OSError
)
as
e
:
current_app
.
logger
.
error
(
e
)
db
.
session
.
rollback
()
raise
e
return
obj
# endregion mixins
# endregion mixins
...
@@ -691,26 +711,6 @@ class JobInput(FileMixin, HashidMixin, db.Model):
...
@@ -691,26 +711,6 @@ class JobInput(FileMixin, HashidMixin, db.Model):
def
user_id
(
self
):
def
user_id
(
self
):
return
self
.
job
.
user_id
return
self
.
job
.
user_id
@staticmethod
def
create
(
input_file
,
**
kwargs
):
filename
=
kwargs
.
get
(
'
filename
'
,
input_file
.
filename
)
mimetype
=
kwargs
.
get
(
'
mimetype
'
,
input_file
.
mimetype
)
job_input
=
JobInput
(
filename
=
secure_filename
(
filename
),
mimetype
=
mimetype
,
**
kwargs
)
db
.
session
.
add
(
job_input
)
db
.
session
.
flush
(
objects
=
[
job_input
])
db
.
session
.
refresh
(
job_input
)
try
:
input_file
.
save
(
job_input
.
path
)
except
OSError
as
e
:
current_app
.
logger
.
error
(
e
)
db
.
session
.
rollback
()
raise
e
return
job_input
def
to_json
(
self
,
backrefs
=
False
,
relationships
=
False
):
def
to_json
(
self
,
backrefs
=
False
,
relationships
=
False
):
_json
=
{
_json
=
{
'
id
'
:
self
.
hashid
,
'
id
'
:
self
.
hashid
,
...
@@ -766,26 +766,6 @@ class JobResult(FileMixin, HashidMixin, db.Model):
...
@@ -766,26 +766,6 @@ class JobResult(FileMixin, HashidMixin, db.Model):
def
user_id
(
self
):
def
user_id
(
self
):
return
self
.
job
.
user_id
return
self
.
job
.
user_id
@staticmethod
def
create
(
input_file
,
**
kwargs
):
filename
=
kwargs
.
get
(
'
filename
'
,
input_file
.
filename
)
mimetype
=
kwargs
.
get
(
'
mimetype
'
,
input_file
.
mimetype
)
job_result
=
JobResult
(
filename
=
secure_filename
(
filename
),
mimetype
=
mimetype
,
**
kwargs
)
db
.
session
.
add
(
job_result
)
db
.
session
.
flush
(
objects
=
[
job_result
])
db
.
session
.
refresh
(
job_result
)
try
:
input_file
.
save
(
job_result
.
path
)
except
OSError
as
e
:
current_app
.
logger
.
error
(
e
)
db
.
session
.
rollback
()
raise
e
return
job_result
def
to_json
(
self
,
backrefs
=
False
,
relationships
=
False
):
def
to_json
(
self
,
backrefs
=
False
,
relationships
=
False
):
_json
=
{
_json
=
{
'
id
'
:
self
.
hashid
,
'
id
'
:
self
.
hashid
,
...
@@ -1024,26 +1004,6 @@ class CorpusFile(FileMixin, HashidMixin, db.Model):
...
@@ -1024,26 +1004,6 @@ class CorpusFile(FileMixin, HashidMixin, db.Model):
_json
[
'
corpus
'
]
=
self
.
corpus
.
to_json
(
backrefs
=
True
)
_json
[
'
corpus
'
]
=
self
.
corpus
.
to_json
(
backrefs
=
True
)
return
_json
return
_json
@staticmethod
def
create
(
input_file
,
**
kwargs
):
filename
=
kwargs
.
pop
(
'
filename
'
,
input_file
.
filename
)
mimetype
=
kwargs
.
pop
(
'
mimetype
'
,
input_file
.
mimetype
)
corpus_file
=
CorpusFile
(
filename
=
secure_filename
(
filename
),
mimetype
=
mimetype
,
**
kwargs
,
)
db
.
session
.
add
(
corpus_file
)
db
.
session
.
flush
(
objects
=
[
corpus_file
])
db
.
session
.
refresh
(
corpus_file
)
try
:
input_file
.
save
(
corpus_file
.
path
)
except
OSError
as
e
:
current_app
.
logger
.
error
(
e
)
db
.
session
.
rollback
()
raise
e
return
corpus_file
class
Corpus
(
HashidMixin
,
db
.
Model
):
class
Corpus
(
HashidMixin
,
db
.
Model
):
'''
'''
Class to define a corpus.
Class to define a corpus.
...
...
This diff is collapsed.
Click to expand it.
app/services/routes.py
+
4
−
4
View file @
2470c8df
...
@@ -45,7 +45,7 @@ def file_setup_pipeline():
...
@@ -45,7 +45,7 @@ def file_setup_pipeline():
for
input_file
in
form
.
images
.
data
:
for
input_file
in
form
.
images
.
data
:
try
:
try
:
JobInput
.
create
(
input_file
,
job
=
job
)
JobInput
.
create
(
input_file
,
job
=
job
)
except
OSError
:
except
(
AttributeError
,
OSError
)
:
abort
(
500
)
abort
(
500
)
job
.
status
=
JobStatus
.
SUBMITTED
job
.
status
=
JobStatus
.
SUBMITTED
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -88,7 +88,7 @@ def tesseract_ocr_pipeline():
...
@@ -88,7 +88,7 @@ def tesseract_ocr_pipeline():
abort
(
500
)
abort
(
500
)
try
:
try
:
JobInput
.
create
(
form
.
pdf
.
data
,
job
=
job
)
JobInput
.
create
(
form
.
pdf
.
data
,
job
=
job
)
except
OSError
:
except
(
AttributeError
,
OSError
)
:
abort
(
500
)
abort
(
500
)
job
.
status
=
JobStatus
.
SUBMITTED
job
.
status
=
JobStatus
.
SUBMITTED
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -138,7 +138,7 @@ def transkribus_htr_pipeline():
...
@@ -138,7 +138,7 @@ def transkribus_htr_pipeline():
abort
(
500
)
abort
(
500
)
try
:
try
:
JobInput
.
create
(
form
.
pdf
.
data
,
job
=
job
)
JobInput
.
create
(
form
.
pdf
.
data
,
job
=
job
)
except
OSError
:
except
(
AttributeError
,
OSError
)
:
abort
(
500
)
abort
(
500
)
job
.
status
=
JobStatus
.
SUBMITTED
job
.
status
=
JobStatus
.
SUBMITTED
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -187,7 +187,7 @@ def spacy_nlp_pipeline():
...
@@ -187,7 +187,7 @@ def spacy_nlp_pipeline():
abort
(
500
)
abort
(
500
)
try
:
try
:
JobInput
.
create
(
form
.
txt
.
data
,
job
=
job
)
JobInput
.
create
(
form
.
txt
.
data
,
job
=
job
)
except
OSError
:
except
(
AttributeError
,
OSError
)
:
abort
(
500
)
abort
(
500
)
job
.
status
=
JobStatus
.
SUBMITTED
job
.
status
=
JobStatus
.
SUBMITTED
db
.
session
.
commit
()
db
.
session
.
commit
()
...
...
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