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
716ebdfa
Commit
716ebdfa
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add create corpus form to dashboard.
parent
a5b7ccae
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/main/views.py
+17
-17
17 additions, 17 deletions
app/main/views.py
app/services/views.py
+18
-20
18 additions, 20 deletions
app/services/views.py
app/templates/main/dashboard.html.j2
+36
-16
36 additions, 16 deletions
app/templates/main/dashboard.html.j2
with
71 additions
and
53 deletions
app/main/views.py
+
17
−
17
View file @
716ebdfa
from
flask
import
current_app
,
flash
,
redirect
,
render_template
,
request
,
url_for
from
datetime
import
datetime
from
flask
import
current_app
,
flash
,
redirect
,
render_template
,
url_for
from
flask_login
import
current_user
,
login_required
from
flask_login
import
current_user
,
login_required
from
..models
import
User
from
..models
import
User
from
..tables
import
AdminUserTable
,
AdminUserItem
from
..tables
import
AdminUserTable
,
AdminUserItem
from
.
import
main
from
.
import
main
from
.forms
import
CreateCorpusForm
from
.forms
import
CreateCorpusForm
from
..decorators
import
admin_required
from
..decorators
import
admin_required
import
hashlib
import
os
import
os
...
@@ -15,25 +17,23 @@ def dashboard():
...
@@ -15,25 +17,23 @@ def dashboard():
if
create_corpus_form
.
validate_on_submit
():
if
create_corpus_form
.
validate_on_submit
():
app
=
current_app
.
_get_current_object
()
app
=
current_app
.
_get_current_object
()
files
=
request
.
FILES
id
=
hashlib
.
md5
(
print
(
files
)
(
current_user
.
username
+
'
_
'
+
datetime
.
now
().
isoformat
()).
encode
()
corpus
=
{
).
hexdigest
()
'
description
'
:
create_corpus_form
.
description
.
data
,
corpus
=
{
'
description
'
:
create_corpus_form
.
description
.
data
,
'
files
'
:
[],
'
id
'
:
id
,
'
owner
'
:
current_user
.
id
,
'
creator
'
:
current_user
.
id
,
'
title
'
:
create_corpus_form
.
title
.
data
'
title
'
:
create_corpus_form
.
title
.
data
}
}
corpus_dir
=
os
.
path
.
join
(
dir
=
os
.
path
.
join
(
app
.
config
[
'
OPAQUE_FILES
'
],
'
corpora
'
,
id
)
app
.
config
[
'
OPAQUE_FILES
'
],
'
corpora
'
,
corpus
[
'
title
'
]
)
try
:
try
:
os
.
m
kdir
(
corpus_
dir
)
os
.
m
akedirs
(
dir
)
except
FileExists
Error
:
except
OS
Error
:
flash
(
'
FileExists
Error
'
)
flash
(
'
OS
Error
!
'
)
else
:
else
:
for
file
in
create_corpus_form
.
files
.
data
:
file
.
save
(
os
.
path
.
join
(
dir
,
file
.
filename
))
flash
(
'
Corpus created!
'
)
flash
(
'
Corpus created!
'
)
return
redirect
(
url_for
(
'
main.dashboard
'
))
return
redirect
(
url_for
(
'
main.dashboard
'
))
...
...
This diff is collapsed.
Click to expand it.
app/services/views.py
+
18
−
20
View file @
716ebdfa
...
@@ -18,32 +18,29 @@ def ocr():
...
@@ -18,32 +18,29 @@ def ocr():
id
=
hashlib
.
md5
(
id
=
hashlib
.
md5
(
(
current_user
.
username
+
'
_
'
+
datetime
.
now
().
isoformat
()).
encode
()
(
current_user
.
username
+
'
_
'
+
datetime
.
now
().
isoformat
()).
encode
()
).
hexdigest
()
).
hexdigest
()
'''
'
TODO: Implement a Job class. For now a dictionary representation
'
is enough.
'''
job
=
{
'
creator
'
:
current_user
.
id
,
'
id
'
:
id
,
'
requested_cpus
'
:
2
,
'
requested_memory
'
:
2048
,
'
service
'
:
'
ocr
'
,
'
service_args
'
:
{
'
lang
'
:
ocr_job_form
.
language
.
data
,
'
version
'
:
'
latest
'
},
'
status
'
:
'
queued
'
}
dir
=
os
.
path
.
join
(
app
.
config
[
'
OPAQUE_FILES
'
],
'
jobs
'
,
id
)
dir
=
os
.
path
.
join
(
app
.
config
[
'
OPAQUE_FILES
'
],
'
jobs
'
,
id
)
try
:
try
:
os
.
mkdir
(
dir
)
os
.
makedirs
(
dir
)
except
FileExistsError
:
except
OSError
:
# Possible MD5 hash collision occurred.
flash
(
'
OSError!
'
)
flash
(
'
Internal error occurred, please try again!
'
)
else
:
else
:
file
=
ocr_job_form
.
file
.
data
file
=
ocr_job_form
.
file
.
data
file
.
save
(
os
.
path
.
join
(
dir
,
file
.
filename
))
file
.
save
(
os
.
path
.
join
(
dir
,
file
.
filename
))
'''
'
TODO: Implement a Job class. For now a dictionary representation
'
is enough.
'''
job
=
{
'
worker
'
:
None
,
'
creator
'
:
current_user
.
id
,
'
id
'
:
id
,
'
requested_cpus
'
:
2
,
'
requested_memory
'
:
2048
,
'
service
'
:
'
ocr
'
,
'
service_args
'
:
{
'
lang
'
:
ocr_job_form
.
language
.
data
,
'
version
'
:
'
latest
'
},
'
status
'
:
'
queued
'
}
'''
'''
'
TODO: Let the scheduler run this job in the background.
'
TODO: Let the scheduler run this job in the background.
'
'
...
@@ -52,6 +49,7 @@ def ocr():
...
@@ -52,6 +49,7 @@ def ocr():
'''
'''
thread
=
Thread
(
target
=
swarm
.
run
,
args
=
(
job
,))
thread
=
Thread
(
target
=
swarm
.
run
,
args
=
(
job
,))
thread
.
start
()
thread
.
start
()
flash
(
'
Job created!
'
)
return
redirect
(
url_for
(
'
services.ocr
'
))
return
redirect
(
url_for
(
'
services.ocr
'
))
return
render_template
(
return
render_template
(
...
...
This diff is collapsed.
Click to expand it.
app/templates/main/dashboard.html.j2
+
36
−
16
View file @
716ebdfa
...
@@ -37,23 +37,43 @@
...
@@ -37,23 +37,43 @@
<div class="col s12">
<div class="col s12">
<div class="card small">
<div class="card small">
<div class="card-content">
<div class="card-content">
<form method="POST">
<form method="POST"
enctype="multipart/form-data"
>
{{ create_corpus_form.hidden_tag() }}
{{ create_corpus_form.hidden_tag() }}
<div class="input-field">
<div class="row">
<i class="material-icons prefix">title</i>
<div class="col s12 m4">
{{ create_corpus_form.title() }}
<div class="input-field">
{{ create_corpus_form.title.label }}
<i class="material-icons prefix">title</i>
{% for error in create_corpus_form.title.errors %}
{{ create_corpus_form.title() }}
<span class="helper-text red-text">{{ error }}</span>
{{ create_corpus_form.title.label }}
{% endfor %}
{% for error in create_corpus_form.title.errors %}
</div>
<span class="helper-text red-text">{{ error }}</span>
<div class="input-field">
{% endfor %}
<i class="material-icons prefix">description</i>
</div>
{{ create_corpus_form.description() }}
</div>
{{ create_corpus_form.description.label }}
<div class="col s12 m8">
{% for error in create_corpus_form.description.errors %}
<div class="input-field">
<span class="helper-text red-text">{{ error }}</span>
<i class="material-icons prefix">description</i>
{% endfor %}
{{ create_corpus_form.description() }}
{{ create_corpus_form.description.label }}
{% for error in create_corpus_form.description.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
</div>
<div class="col s12">
<div class="file-field input-field">
<div class="btn">
<span>{{ create_corpus_form.files.label.text }}</span>
{{ create_corpus_form.files(accept='.vrt') }}
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
{% for error in create_corpus_form.files.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
</div>
</div>
</div>
<div class="card-action right-align">
<div class="card-action right-align">
{{ create_corpus_form.submit(class='btn') }}
{{ create_corpus_form.submit(class='btn') }}
...
...
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