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
9710d33e
Commit
9710d33e
authored
4 years ago
by
Sabine Schröder
Browse files
Options
Downloads
Patches
Plain Diff
#9
: changed patch syntax to standard way; fixed patch for adding roles
parent
5b112a36
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#47348
passed
4 years ago
Stage: deploy
Stage: pages
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
toardb/stationmeta/crud.py
+17
-10
17 additions, 10 deletions
toardb/stationmeta/crud.py
toardb/stationmeta/schemas.py
+7
-11
7 additions, 11 deletions
toardb/stationmeta/schemas.py
toardb/stationmeta/stationmeta.py
+6
-12
6 additions, 12 deletions
toardb/stationmeta/stationmeta.py
with
30 additions
and
33 deletions
toardb/stationmeta/crud.py
+
17
−
10
View file @
9710d33e
...
@@ -174,7 +174,7 @@ def create_stationmeta(db: Session, stationmeta: StationmetaCreate):
...
@@ -174,7 +174,7 @@ def create_stationmeta(db: Session, stationmeta: StationmetaCreate):
db_stationmeta
.
coordinates
=
tmp_coordinates
db_stationmeta
.
coordinates
=
tmp_coordinates
return
db_stationmeta
return
db_stationmeta
def
patch_stationmeta
(
db
:
Session
,
station
meta_core
_id
:
int
,
stationmeta
:
StationmetaPatch
):
def
patch_stationmeta
(
db
:
Session
,
station_id
:
int
,
stationmeta
:
StationmetaPatch
):
stationmeta_dict
=
stationmeta
.
dict
()
stationmeta_dict
=
stationmeta
.
dict
()
roles_data
=
stationmeta_dict
.
pop
(
'
roles
'
,
None
)
roles_data
=
stationmeta_dict
.
pop
(
'
roles
'
,
None
)
annotations_data
=
stationmeta_dict
.
pop
(
'
annotations
'
,
None
)
annotations_data
=
stationmeta_dict
.
pop
(
'
annotations
'
,
None
)
...
@@ -187,10 +187,10 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
...
@@ -187,10 +187,10 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
# ==> the following two commands are not working
# ==> the following two commands are not working
# ==> workaround
# ==> workaround
# stationmeta_dict2 = {k: v for k, v in stationmeta_dict.items() if v is not None}
# stationmeta_dict2 = {k: v for k, v in stationmeta_dict.items() if v is not None}
# db.query(models.StationmetaCore).filter(models.StationmetaCore.id == stationm
eta_core
_id).update(stationmeta_dict2)
# db.query(models.StationmetaCore).filter(models.StationmetaCore.id == stationm_id).update(stationmeta_dict2)
db_obj
=
models
.
StationmetaCore
(
**
stationmeta_dict
)
db_obj
=
models
.
StationmetaCore
(
**
stationmeta_dict
)
tmp_coordinates
=
db_obj
.
coordinates
tmp_coordinates
=
db_obj
.
coordinates
db_stationmeta
=
db
.
query
(
models
.
StationmetaCore
).
get
(
station
meta_core
_id
)
db_stationmeta
=
db
.
query
(
models
.
StationmetaCore
).
get
(
station_id
)
db_stationmeta
.
coordinates
=
get_geom_from_coordinates
(
db_stationmeta
.
coordinates
)
db_stationmeta
.
coordinates
=
get_geom_from_coordinates
(
db_stationmeta
.
coordinates
)
for
k
,
v
in
stationmeta_dict
.
items
():
for
k
,
v
in
stationmeta_dict
.
items
():
if
v
is
not
None
:
if
v
is
not
None
:
...
@@ -207,12 +207,19 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
...
@@ -207,12 +207,19 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
db_object
=
get_unique_stationmeta_role
(
db
,
db_role
.
role
,
db_role
.
contact_id
,
db_role
.
status
)
db_object
=
get_unique_stationmeta_role
(
db
,
db_role
.
role
,
db_role
.
contact_id
,
db_role
.
status
)
if
db_object
:
if
db_object
:
role_id
=
db_object
.
id
role_id
=
db_object
.
id
print
(
"
found role_id:
"
,
role_id
)
else
:
else
:
print
(
"
did not find role: now inserting new role
"
)
print
(
r
)
print
(
db_role
.
role
)
print
(
db_role
.
status
)
print
(
db_role
.
contact_id
)
db
.
add
(
db_role
)
db
.
add
(
db_role
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_role
)
db
.
refresh
(
db_role
)
role_id
=
db_role
.
id
role_id
=
db_role
.
id
db
.
execute
(
insert
(
stationmeta_core_stationmeta_roles_table
).
values
(
station_id
=
stationmeta_core_id
,
role_id
=
role_id
))
print
(
"
did not find role: inserted new role_id
"
,
role_id
)
db
.
execute
(
insert
(
stationmeta_core_stationmeta_roles_table
).
values
(
station_id
=
station_id
,
role_id
=
role_id
))
db
.
commit
()
db
.
commit
()
# store annotations and update association table
# store annotations and update association table
if
annotations_data
:
if
annotations_data
:
...
@@ -227,13 +234,13 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
...
@@ -227,13 +234,13 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_annotation
)
db
.
refresh
(
db_annotation
)
annotation_id
=
db_annotation
.
id
annotation_id
=
db_annotation
.
id
db
.
execute
(
insert
(
stationmeta_core_stationmeta_annotations_table
).
values
(
station_id
=
station
meta_core
_id
,
annotation_id
=
annotation_id
))
db
.
execute
(
insert
(
stationmeta_core_stationmeta_annotations_table
).
values
(
station_id
=
station_id
,
annotation_id
=
annotation_id
))
db
.
commit
()
db
.
commit
()
# store aux_images
# store aux_images
if
aux_images_data
:
if
aux_images_data
:
for
i
in
aux_images_data
:
for
i
in
aux_images_data
:
db_aux_image
=
models
.
StationmetaAuxImage
(
**
i
)
db_aux_image
=
models
.
StationmetaAuxImage
(
**
i
)
db_aux_image
.
station_id
=
station
meta_core
_id
db_aux_image
.
station_id
=
station_id
db
.
add
(
db_aux_image
)
db
.
add
(
db_aux_image
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_aux_image
)
db
.
refresh
(
db_aux_image
)
...
@@ -241,7 +248,7 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
...
@@ -241,7 +248,7 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
if
aux_docs_data
:
if
aux_docs_data
:
for
d
in
aux_docs_data
:
for
d
in
aux_docs_data
:
db_aux_doc
=
models
.
StationmetaAuxDoc
(
**
d
)
db_aux_doc
=
models
.
StationmetaAuxDoc
(
**
d
)
db_aux_doc
.
station_id
=
station
meta_core
_id
db_aux_doc
.
station_id
=
station_id
db
.
add
(
db_aux_doc
)
db
.
add
(
db_aux_doc
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_aux_doc
)
db
.
refresh
(
db_aux_doc
)
...
@@ -249,7 +256,7 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
...
@@ -249,7 +256,7 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
if
aux_urls_data
:
if
aux_urls_data
:
for
u
in
aux_urls_data
:
for
u
in
aux_urls_data
:
db_aux_url
=
models
.
StationmetaAuxUrl
(
**
u
)
db_aux_url
=
models
.
StationmetaAuxUrl
(
**
u
)
db_aux_url
.
station_id
=
station
meta_core
_id
db_aux_url
.
station_id
=
station_id
db
.
add
(
db_aux_url
)
db
.
add
(
db_aux_url
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_aux_url
)
db
.
refresh
(
db_aux_url
)
...
@@ -258,14 +265,14 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
...
@@ -258,14 +265,14 @@ def patch_stationmeta(db: Session, stationmeta_core_id: int, stationmeta: Statio
db_global
=
models
.
StationmetaGlobal
(
**
globalmeta_data
)
db_global
=
models
.
StationmetaGlobal
(
**
globalmeta_data
)
if
db_global
.
climatic_zone
:
if
db_global
.
climatic_zone
:
db_global
.
climatic_zone
=
get_value_from_str
(
CZ_enum
,
db_global
.
climatic_zone
)
db_global
.
climatic_zone
=
get_value_from_str
(
CZ_enum
,
db_global
.
climatic_zone
)
db_global
.
station_id
=
station
meta_core
_id
db_global
.
station_id
=
station_id
db
.
add
(
db_global
)
db
.
add
(
db_global
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_global
)
db
.
refresh
(
db_global
)
# store globalservice
# store globalservice
if
globalservice_data
:
if
globalservice_data
:
db_globalservice
=
models
.
StationmetaGlobalService
(
**
globalservice
)
db_globalservice
=
models
.
StationmetaGlobalService
(
**
globalservice
)
db_globalservice
.
station_id
=
station
meta_core
_id
db_globalservice
.
station_id
=
station_id
db
.
add
(
db_globalservice
)
db
.
add
(
db_globalservice
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_globalservice
)
db
.
refresh
(
db_globalservice
)
...
...
This diff is collapsed.
Click to expand it.
toardb/stationmeta/schemas.py
+
7
−
11
View file @
9710d33e
...
@@ -411,17 +411,13 @@ class StationmetaRoleBase(BaseModel):
...
@@ -411,17 +411,13 @@ class StationmetaRoleBase(BaseModel):
class
StationmetaRolePatch
(
BaseModel
):
class
StationmetaRolePatch
(
BaseModel
):
role
:
str
=
None
role
:
str
status
:
str
=
None
status
:
str
contact
:
Contact
=
None
# at the moment contact_id has to be given...
# ==> in the future: give unique contact_email
@validator
(
'
role
'
)
# patching stationmeta should not result in creating new contacts!
def
check_role
(
cls
,
v
):
# ==> still to do: check, whether contact already exists (otherwise patching cannot be done)
return
tuple
(
filter
(
lambda
x
:
x
.
value
==
int
(
v
),
RC_enum
))[
0
].
string
contact_id
:
int
@validator
(
'
status
'
)
def
check_status
(
cls
,
v
):
return
tuple
(
filter
(
lambda
x
:
x
.
value
==
int
(
v
),
RS_enum
))[
0
].
string
class
Config
:
class
Config
:
orm_mode
=
True
orm_mode
=
True
...
...
This diff is collapsed.
Click to expand it.
toardb/stationmeta/stationmeta.py
+
6
−
12
View file @
9710d33e
...
@@ -59,15 +59,9 @@ def create_stationmeta_core(stationmeta: schemas.StationmetaCreate = Body(..., e
...
@@ -59,15 +59,9 @@ def create_stationmeta_core(stationmeta: schemas.StationmetaCreate = Body(..., e
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Station already registered.
"
)
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Station already registered.
"
)
return
crud
.
create_stationmeta
(
db
=
db
,
stationmeta
=
stationmeta
)
return
crud
.
create_stationmeta
(
db
=
db
,
stationmeta
=
stationmeta
)
@router.patch
(
'
/stationmeta/
'
,
response_model
=
schemas
.
StationmetaPatch
)
@router.patch
(
'
/stationmeta/{station_code}
'
,
response_model
=
schemas
.
StationmetaPatch
)
def
patch_stationmeta_core
(
stationmeta
:
schemas
.
StationmetaPatch
=
Body
(...,
embed
=
True
),
db
:
Session
=
Depends
(
get_db
)):
def
patch_stationmeta_core
(
station_code
:
str
,
stationmeta
:
schemas
.
StationmetaPatch
=
Body
(...,
embed
=
True
),
db
:
Session
=
Depends
(
get_db
)):
found
=
False
db_stationmeta
=
crud
.
get_stationmeta
(
db
,
station_code
=
station_code
)
for
station_code
in
stationmeta
.
codes
:
if
db_stationmeta
is
None
:
if
not
found
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"
Station for patching not found.
"
)
db_stationmeta_core
=
crud
.
get_stationmeta_core
(
db
,
station_code
=
station_code
)
return
crud
.
patch_stationmeta
(
db
=
db
,
station_id
=
db_stationmeta
.
id
,
stationmeta
=
stationmeta
)
if
db_stationmeta_core
:
found
=
True
if
found
:
return
crud
.
patch_stationmeta
(
db
=
db
,
stationmeta_core_id
=
db_stationmeta_core
.
id
,
stationmeta
=
stationmeta
)
else
:
raise
HTTPException
(
status_code
=
400
,
detail
=
"
Station not found!
"
)
This diff is collapsed.
Click to expand it.
Sabine Schröder
@schroeder5
mentioned in issue
#9 (closed)
·
4 years ago
mentioned in issue
#9 (closed)
mentioned in issue #9
Toggle commit list
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