Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Commits
b68647c7
Commit
b68647c7
authored
Mar 22, 2021
by
Eirik Martin Danielsen
Browse files
Options
Downloads
Patches
Plain Diff
update and delete location
parent
18abc23a
No related branches found
No related tags found
1 merge request
!37
Resolve "rematch function and endpoint"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/endpoints/location.py
+53
-2
53 additions, 2 deletions
api/endpoints/location.py
with
53 additions
and
2 deletions
api/endpoints/location.py
+
53
−
2
View file @
b68647c7
from
flask
import
request
,
jsonify
from
flask
import
request
,
jsonify
from
flask_restful
import
Resource
from
flask_restful
import
Resource
from
flask_jwt_extended
import
jwt_required
from
flask_jwt_extended
import
jwt_required
,
get_jwt_identity
from
api.models.dbmodels
import
User
from
api
import
db
from
api
import
db
from
api
import
limiter
from
api
import
limiter
from
api.models.dbmodels
import
Location
from
api.models.dbmodels
import
Location
,
Salamander
import
re
import
re
import
os
import
os
from
api.endpoints.matchsalamander
import
sanitize_int_str
from
api.endpoints.matchsalamander
import
sanitize_int_str
...
@@ -42,6 +44,55 @@ class LocationEndpoint(Resource):
...
@@ -42,6 +44,55 @@ class LocationEndpoint(Resource):
location_list
.
append
(
loc
)
location_list
.
append
(
loc
)
return
jsonify
({
"
locations
"
:
location_list
,
"
status
"
:
200
})
return
jsonify
({
"
locations
"
:
location_list
,
"
status
"
:
200
})
@staticmethod
@jwt_required
def
delete
():
user_id
=
get_jwt_identity
()
user
=
db
.
session
.
query
(
User
).
filter_by
(
id
=
user_id
).
first
()
data
=
request
.
form
if
user
.
admin
:
if
"
id
"
in
data
:
salamanders
=
db
.
session
.
query
(
Salamander
).
filter_by
(
location_id
=
data
[
'
id
'
])
if
salamanders
and
len
(
salamanders
)
==
0
:
location
=
db
.
session
.
query
(
Location
).
filter_by
(
id
=
data
[
'
id
'
]).
first
()
if
location
:
db
.
session
.
delete
(
location
)
db
.
session
.
commit
()
return
jsonify
({
"
location
"
:
str
(
location
.
id
),
"
deleted
"
:
200
})
else
:
return
jsonify
({
"
message
"
:
"
location doesn
'
t exist
"
,
"
status
"
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
location needs to be empty
"
,
"
status
"
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
wrong data
"
,
"
status
"
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
user not admin
"
,
"
status
"
:
400
})
@staticmethod
@jwt_required
def
put
():
user_id
=
get_jwt_identity
()
user
=
db
.
session
.
query
(
User
).
filter_by
(
id
=
user_id
).
first
()
data
=
request
.
form
if
user
.
admin
:
if
"
id
"
in
data
:
location
=
db
.
session
.
query
(
Location
).
filter_by
(
id
=
data
[
'
id
'
]).
first
()
if
location
:
if
"
new_name
"
in
data
:
location
.
name
=
data
[
'
new_radius
'
].
lower
()
if
"
new_radius
"
in
data
:
location
.
radius
=
sanitize_int_str
(
str
(
data
[
'
new_radius
'
]))
if
"
new_latitude
"
in
data
:
location
.
latitude
=
data
[
'
new_latitude
'
]
if
"
new_longitude
"
in
data
:
location
.
longitude
=
data
[
'
new_longitude
'
]
db
.
session
.
commit
()
return
jsonify
({
"
location
"
:
str
(
location
.
id
),
"
updated.
"
:
200
})
else
:
return
jsonify
({
"
message
"
:
"
location doesn
'
t exist
"
,
"
status
"
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
wrong data
"
,
"
status
"
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
user not admin
"
,
"
status
"
:
400
})
def
create_directory_folders
(
location
):
def
create_directory_folders
(
location
):
dir_smooth_male
=
"
images/
"
+
location
+
"
/smooth_newt/
"
+
"
male/
"
dir_smooth_male
=
"
images/
"
+
location
+
"
/smooth_newt/
"
+
"
male/
"
...
...
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