Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TOAR-II FastAPI
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
esde
toar-data
TOAR-II FastAPI
Commits
e2ebce2b
Commit
e2ebce2b
authored
4 years ago
by
Sabine Schröder
Browse files
Options
Downloads
Patches
Plain Diff
#9
: patch API for deleting fields inserts a changelog entry
parent
90d30342
No related branches found
No related tags found
No related merge requests found
Pipeline
#48110
passed
4 years ago
Stage: deploy
Stage: pages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
toardb/stationmeta/crud.py
+26
-6
26 additions, 6 deletions
toardb/stationmeta/crud.py
toardb/stationmeta/stationmeta.py
+1
-1
1 addition, 1 deletion
toardb/stationmeta/stationmeta.py
with
27 additions
and
7 deletions
toardb/stationmeta/crud.py
+
26
−
6
View file @
e2ebce2b
...
...
@@ -195,6 +195,13 @@ def create_stationmeta(db: Session, stationmeta: StationmetaCreate):
db_stationmeta
.
coordinates
=
tmp_coordinates
return
db_stationmeta
def
get_field_from_record
(
db
,
station_id
,
field
,
db_stationmeta
):
if
field
in
[
'
roles
'
,
'
annotations
'
,
'
aux_images
'
,
'
aux_docs
'
,
'
aux_urls
'
,
'
globalmeta
'
]:
field
=
f
"'
{
field
}
'
:
"
+
str
(
getattr
(
db_stationmeta
,
field
))
else
:
field
=
f
"'
{
field
}
'
:
"
+
str
(
getattr
(
db_stationmeta
,
field
))
return
field
def
patch_stationmeta
(
db
:
Session
,
description
:
str
,
station_id
:
int
,
stationmeta
:
StationmetaPatch
):
stationmeta_dict
=
stationmeta
.
dict
()
# delete empty fields from stationmeta_dict already at this place, to be able to
...
...
@@ -227,9 +234,9 @@ def patch_stationmeta(db: Session, description: str, station_id: int, stationmet
if
v
is
not
None
:
# prepare changelog entry
if
(
number_of_commas
==
0
):
old_value
=
old_value
+
f
"'
{
k
}
'
:
"
+
str
(
getattr
(
db_stationmeta
,
k
)
)
+
'
}
'
old_value
=
old_value
+
get_field_from_record
(
db
,
station_id
,
k
,
db_stationmeta
)
+
'
}
'
else
:
old_value
=
old_value
+
f
"'
{
k
}
'
:
"
+
str
(
getattr
(
db_stationmeta
,
k
)
)
+
'
,
'
old_value
=
old_value
+
get_field_from_record
(
db
,
station_id
,
k
,
db_stationmeta
)
+
'
,
'
number_of_commas
=
number_of_commas
-
1
setattr
(
db_stationmeta
,
k
,
stationmeta_dict
[
k
])
result
=
db
.
commit
()
...
...
@@ -344,15 +351,28 @@ def patch_stationmeta(db: Session, description: str, station_id: int, stationmet
return
db_stationmeta
def
delete_stationmeta_field
(
db
:
Session
,
station_id
:
int
,
keyword
:
str
):
if
keyword
==
'
roles
'
:
db
.
execute
(
delete
(
stationmeta_core_stationmeta_roles_table
).
where
(
stationmeta_core_stationmeta_roles_table
.
c
.
station_id
==
station_id
))
# stationmeta_core_stationmeta_roles_table.delete().where(stationmeta_core_stationmeta_roles_table.c.station_id==station_id)
def
delete_stationmeta_field
(
db
:
Session
,
station_id
:
int
,
field
:
str
):
field_table
=
{
'
roles
'
:
stationmeta_core_stationmeta_roles_table
,
'
annotations
'
:
stationmeta_core_stationmeta_annotations_table
}
# 'aux_images': stationmeta_core_stationmeta_aux_images_table,
# 'aux_docs': stationmeta_core_stationmeta_aux_docs_table,
# 'aux_urls': stationmeta_core_stationmeta_aux_urls_table,
# 'globalmeta': stationmeta_core_stationmeta_globalmeta_table}
# there are mandatory fields (from stationmeta_core), that cannot be deleted!
if
((
field
==
'
roles
'
)
or
(
field
==
'
annotations
'
)):
db
.
execute
(
delete
(
field_table
[
field
]).
where
(
field_table
[
field
].
c
.
station_id
==
station_id
))
# problem with automatic conversion of coordinates (although not explicitly fetched from database)
# ==> next two lines are a workaround
db_stationmeta
=
db
.
query
(
models
.
StationmetaCore
).
get
(
station_id
)
tmp_coordinates
=
db_stationmeta
.
coordinates
db_stationmeta
.
coordinates
=
get_geom_from_coordinates
(
db_stationmeta
.
coordinates
)
# also write changelog entry
type_of_change
=
get_value_from_str
(
CL_enum
,
"
SingleValue
"
)
description
=
f
"
delete field
{
field
}
"
old_value
=
get_field_from_record
(
db
,
station_id
,
field
,
db_stationmeta
)
db_changelog
=
StationmetaChangelog
(
description
=
description
,
station_id
=
station_id
,
author_id
=
1
,
type_of_change
=
type_of_change
,
old_value
=
old_value
,
new_value
=
""
)
db
.
add
(
db_changelog
)
db
.
commit
()
# there's a mismatch with coordinates --> how to automatically switch back and forth?!
db_stationmeta
.
coordinates
=
tmp_coordinates
...
...
This diff is collapsed.
Click to expand it.
toardb/stationmeta/stationmeta.py
+
1
−
1
View file @
e2ebce2b
...
...
@@ -76,4 +76,4 @@ def patch_stationmeta_core(station_code: str, field: str, db: Session = Depends(
db_stationmeta
=
crud
.
get_stationmeta
(
db
,
station_code
=
station_code
)
if
db_stationmeta
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"
Station for deleting field not found.
"
)
return
crud
.
delete_stationmeta_field
(
db
=
db
,
station_id
=
db_stationmeta
.
id
,
keywor
d
=
field
)
return
crud
.
delete_stationmeta_field
(
db
=
db
,
station_id
=
db_stationmeta
.
id
,
fiel
d
=
field
)
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