Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue analytics
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
caosdb
Software
caosdb-pylib
Commits
6901905e
Commit
6901905e
authored
Feb 25, 2022
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: handling of sub properties
parent
abcb30a7
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/high_level_api.py
+45
-21
45 additions, 21 deletions
src/caosdb/high_level_api.py
with
45 additions
and
21 deletions
src/caosdb/high_level_api.py
+
45
−
21
View file @
6901905e
...
...
@@ -206,6 +206,7 @@ class CaosDBPythonEntity(object):
val
,
datatype
=
ent
.
datatype
)
metadata
=
self
.
get_property_metadata
(
ent
.
name
)
for
prop_name
in
fields
(
metadata
):
k
=
prop_name
.
name
if
k
==
"
importance
"
:
...
...
@@ -328,6 +329,11 @@ class CaosDBPythonEntity(object):
if
val
is
None
:
return
None
elif
isinstance
(
val
,
db
.
Entity
):
# this needs to be checked as second case as it is the ONLY
# case which does not depend on pr
# TODO: we might need to pass through the reference container
return
convert_to_python_object
(
val
)
elif
pr
is
None
:
return
val
elif
pr
==
DOUBLE
:
...
...
@@ -346,8 +352,6 @@ class CaosDBPythonEntity(object):
return
self
.
_parse_datetime
(
val
)
elif
is_list_datatype
(
pr
):
return
self
.
_type_converted_list
(
val
,
pr
)
elif
isinstance
(
val
,
db
.
Entity
):
return
convert_to_python_object
(
val
)
else
:
# Generic references to entities:
return
CaosDBPythonUnresolvedReference
(
val
)
...
...
@@ -558,7 +562,8 @@ BASE_ATTRIBUTES = (
def
_single_convert_to_python_object
(
robj
:
CaosDBPythonEntity
,
entity
:
db
.
Entity
):
entity
:
db
.
Entity
,
references
:
db
.
Container
=
None
):
"""
Convert a db.Entity from the standard API to a (previously created)
CaosDBPythonEntity from the high level API.
...
...
@@ -566,6 +571,11 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
This method will not resolve any unresolved references, so reference properties
as well as parents will become unresolved references in the first place.
The optional third parameter can be used
to resolve references that occur in the converted entities and resolve them
to their correct representations. (Entities that are not found remain as
CaosDBPythonUnresolvedReferences.)
Returns the input object robj.
"""
for
base_attribute
in
BASE_ATTRIBUTES
:
...
...
@@ -579,6 +589,9 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
robj
.
add_parent
(
CaosDBPythonUnresolvedParent
(
id
=
parent
.
id
,
name
=
parent
.
name
))
# Resolve so far unresolved references also using the provided references container:
# TODO
return
robj
...
...
@@ -682,6 +695,7 @@ def _single_convert_to_entity(entity: db.Entity,
def
convert_to_entity
(
python_object
,
**
kwargs
):
raise
NotImplementedError
()
if
isinstance
(
python_object
,
db
.
Container
):
# Create a list of objects:
...
...
@@ -700,24 +714,34 @@ def convert_to_entity(python_object, **kwargs):
raise
ValueError
(
"
Cannot convert an object of this type.
"
)
def
convert_to_python_object
(
entity
):
""""""
def
convert_to_python_object
(
entity
:
Union
[
db
.
Container
,
db
.
Entity
],
references
:
db
.
Container
=
None
):
"""
Convert either a container of CaosDB entities or a single CaosDB entity
into the high level representation.
The optional second parameter can be used
to resolve references that occur in the converted entities and resolve them
to their correct representations. (Entities that are not found remain as
CaosDBPythonUnresolvedReferences.)
"""
# TODO: check appropriateness of python classes as dict keys:
entity_map
=
{
db
.
Record
:
CaosDBPythonRecord
,
db
.
RecordType
:
CaosDBPythonRecordType
,
db
.
File
:
CaosDBPythonFile
,
db
.
Property
:
CaosDBPythonProperty
,
db
.
Entity
:
CaosDBPythonEntity
}
if
isinstance
(
entity
,
db
.
Container
):
# Create a list of objects:
return
[
convert_to_python_object
(
i
,
references
)
for
i
in
entity
]
return
[
convert_to_python_object
(
i
)
for
i
in
entity
]
elif
isinstance
(
entity
,
db
.
Record
):
return
_single_convert_to_python_object
(
CaosDBPythonRecord
(),
entity
)
elif
isinstance
(
entity
,
db
.
RecordType
):
for
entity_type
in
entity_map
:
if
isinstance
(
entity
,
entity_type
):
# TODO: mypy fails here, the case "db.Container" is already treated above
return
_single_convert_to_python_object
(
CaosDBPythonRecordType
(),
entity
)
elif
isinstance
(
entity
,
db
.
File
):
return
_single_convert_to_python_object
(
CaosDBPythonFile
(),
entity
)
elif
isinstance
(
entity
,
db
.
Property
):
return
_single_convert_to_python_object
(
CaosDBPythonProperty
(),
entity
)
elif
isinstance
(
entity
,
db
.
Entity
):
return
_single_convert_to_python_object
(
CaosDBPythonEntity
(),
entity
)
else
:
entity_map
[
entity_type
](),
entity
,
references
)
raise
ValueError
(
"
Cannot convert an object of this type.
"
)
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