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
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
09fdad21
Commit
09fdad21
authored
2 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Standardize code for reference
parent
92721502
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/contributions/routes.py
+32
-22
32 additions, 22 deletions
app/contributions/routes.py
with
32 additions
and
22 deletions
app/contributions/routes.py
+
32
−
22
View file @
09fdad21
...
...
@@ -110,7 +110,10 @@ def spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id):
)
#region json-routes
@bp.route
(
'
/spacy-nlp-pipeline-models/<hashid:spacy_nlp_pipeline_model_id>
'
,
methods
=
[
'
DELETE
'
])
@login_required
@content_negotiation
(
produces
=
'
application/json
'
)
def
delete_spacy_model
(
spacy_nlp_pipeline_model_id
):
def
_delete_spacy_model
(
app
,
spacy_nlp_pipeline_model_id
):
with
app
.
app_context
():
...
...
@@ -118,18 +121,21 @@ def delete_spacy_model(spacy_nlp_pipeline_model_id):
spacy_nlp_pipeline_model
.
delete
()
db
.
session
.
commit
()
s
pacy_nlp_pipeline_model
=
SpaCyNLPPipelineModel
.
query
.
get_or_404
(
spacy_nlp_pipeline_model_id
)
if
not
(
s
pacy_nlp_pipeline_model
.
user
==
current_user
or
current_user
.
is_administrator
()):
s
npm
=
SpaCyNLPPipelineModel
.
query
.
get_or_404
(
spacy_nlp_pipeline_model_id
)
if
not
(
s
npm
.
user
==
current_user
or
current_user
.
is_administrator
()):
abort
(
403
)
thread
=
Thread
(
target
=
_delete_spacy_model
,
args
=
(
current_app
.
_get_current_object
(),
spacy_nlp_pipeline_model_id
)
)
thread
.
start
()
return
{},
202
response
=
jsonify
(
f
'
SpaCy NLP Pipeline Model
"
{
snpm
.
title
}
"
marked for deletion
'
)
response
.
status_code
=
202
return
response
#region json-routes
@bp.route
(
'
/spacy-nlp-pipeline-models/<hashid:spacy_nlp_pipeline_model_id>/is_public
'
,
methods
=
[
'
PUT
'
])
@login_required
@permission_required
(
'
CONTRIBUTE
'
)
...
...
@@ -137,15 +143,14 @@ def delete_spacy_model(spacy_nlp_pipeline_model_id):
def
update_spacy_nlp_pipeline_model_is_public
(
spacy_nlp_pipeline_model_id
):
is_public
=
request
.
json
if
not
isinstance
(
is_public
,
bool
):
response
=
jsonify
(
'
The request body must be a boolean
'
)
response
.
status_code
=
400
abort
(
response
)
spacy_nlp_pipeline_model
=
\
SpaCyNLPPipelineModel
.
query
.
get_or_404
(
spacy_nlp_pipeline_model_id
)
spacy_nlp_pipeline_model
.
is_public
=
is_public
abort
(
400
)
snpm
=
SpaCyNLPPipelineModel
.
query
.
get_or_404
(
spacy_nlp_pipeline_model_id
)
if
not
(
snpm
.
user
==
current_user
or
current_user
.
is_administrator
()):
abort
(
403
)
snpm
.
is_public
=
is_public
db
.
session
.
commit
()
response
=
jsonify
(
f
'
SpaCy NLP Pipeline Model
"
{
s
pacy_nlp_pipeline_model
.
title
}
"'
f
'
SpaCy NLP Pipeline Model
"
{
s
npm
.
title
}
"'
f
'
is now
{
"
public
"
if
is_public
else
"
private
"
}
'
)
response
.
status_code
=
200
...
...
@@ -225,7 +230,10 @@ def tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id):
)
#region json-routes
@bp.route
(
'
/tesseract-ocr-pipeline-models/<hashid:tesseract_ocr_pipeline_model_id>
'
,
methods
=
[
'
DELETE
'
])
@login_required
@content_negotiation
(
produces
=
'
application/json
'
)
def
delete_tesseract_model
(
tesseract_ocr_pipeline_model_id
):
def
_delete_tesseract_ocr_pipeline_model
(
app
,
tesseract_ocr_pipeline_model_id
):
with
app
.
app_context
():
...
...
@@ -233,18 +241,21 @@ def delete_tesseract_model(tesseract_ocr_pipeline_model_id):
tesseract_ocr_pipeline_model
.
delete
()
db
.
session
.
commit
()
t
esseract_ocr_pipeline_model
=
TesseractOCRPipelineModel
.
query
.
get_or_404
(
tesseract_ocr_pipeline_model_id
)
if
not
(
t
esseract_ocr_pipeline_model
.
user
==
current_user
or
current_user
.
is_administrator
()):
t
opm
=
TesseractOCRPipelineModel
.
query
.
get_or_404
(
tesseract_ocr_pipeline_model_id
)
if
not
(
t
opm
.
user
==
current_user
or
current_user
.
is_administrator
()):
abort
(
403
)
thread
=
Thread
(
target
=
_delete_tesseract_ocr_pipeline_model
,
args
=
(
current_app
.
_get_current_object
(),
tesseract_ocr_pipeline_model_id
)
)
thread
.
start
()
return
{},
202
response
=
jsonify
(
f
'
Tesseract OCR Pipeline Model
"
{
topm
.
title
}
"
marked for deletion
'
)
response
.
status_code
=
200
return
response
#region json-routes
@bp.route
(
'
/tesseract-ocr-pipeline-models/<hashid:tesseract_ocr_pipeline_model_id>/is_public
'
,
methods
=
[
'
PUT
'
])
@login_required
@permission_required
(
'
CONTRIBUTE
'
)
...
...
@@ -252,15 +263,14 @@ def delete_tesseract_model(tesseract_ocr_pipeline_model_id):
def
update_tesseract_ocr_pipeline_model_is_public
(
tesseract_ocr_pipeline_model_id
):
is_public
=
request
.
json
if
not
isinstance
(
is_public
,
bool
):
response
=
jsonify
(
'
The request body must be a boolean
'
)
response
.
status_code
=
400
abort
(
response
)
tesseract_ocr_pipeline_model
=
\
TesseractOCRPipelineModel
.
query
.
get_or_404
(
tesseract_ocr_pipeline_model_id
)
tesseract_ocr_pipeline_model
.
is_public
=
is_public
abort
(
400
)
topm
=
TesseractOCRPipelineModel
.
query
.
get_or_404
(
tesseract_ocr_pipeline_model_id
)
if
not
(
topm
.
user
==
current_user
or
current_user
.
is_administrator
()):
abort
(
403
)
topm
.
is_public
=
is_public
db
.
session
.
commit
()
response
=
jsonify
(
f
'
Tesseract OCR Pipeline Model
"
{
t
esseract_ocr_pipeline_model
.
title
}
"'
f
'
Tesseract OCR Pipeline Model
"
{
t
opm
.
title
}
"'
f
'
is now
{
"
public
"
if
is_public
else
"
private
"
}
'
)
response
.
status_code
=
200
...
...
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