Skip to content
Snippets Groups Projects
Commit 1bc2c28e authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

ENH: more information from Properties is added to metadata now

parent 4fea5909
No related branches found
No related tags found
2 merge requests!57RELEASE 0.7.3,!52F refactor high level api
Pipeline #19509 canceled
......@@ -41,7 +41,7 @@ from .apiutils import get_type_of_entity_with
from typing import Any, Optional, List, Union, Dict
from dataclasses import dataclass
from dataclasses import dataclass, fields
from datetime import datetime
@dataclass
......@@ -74,7 +74,6 @@ class CaosDBPythonUnresolvedReference:
def __init__(self, id=None):
self.id = id
class CaosDBPythonEntity(object):
_last_id = 0
......@@ -129,7 +128,7 @@ class CaosDBPythonEntity(object):
@name.setter
def name(self, val: str):
self._name = name
self._name = val
@property
def description(self):
......@@ -140,7 +139,7 @@ class CaosDBPythonEntity(object):
@description.setter
def description(self, val: str):
self._description = description
self._description = val
@property
def version(self):
......@@ -168,11 +167,15 @@ class CaosDBPythonEntity(object):
The entity to be set.
"""
name = ent.name
val = ent.value
pr = ent.datatype
val, reference = self._type_converted_value(val, pr)
self.set_property(name, val, reference, datatype=pr)
val = self._type_converted_value(ent.value, ent.datatype)
metadata = self.get_property_metadata(ent.name)
for prop_name in fields(metadata):
k = prop_name.name
metadata.__setattr__(k, ent.__getattribute__(k))
self.set_property(
ent.name,
val,
datatype=ent.datatype)
def get_property_metadata(self, prop_name: str) -> CaosDBPropertyMetaData:
"""
......@@ -223,21 +226,8 @@ class CaosDBPythonEntity(object):
overwrite: bool
Use this if you definitely only want one property with
that name (set to True).
datatype: Optional[str]
"""
# Store the datatype (if given) in a hidden field
# The datatypes will be stored in name, value pairs.
# TODO: check whether handling of lists and multi properties is correct.
metadata = self.get_property_metadata(name)
metadata.datatype = datatype
if isinstance(name, db.Entity):
# TODO: check, whether this is reasonable?
name = name.name
raise NotImplementedError()
if name in self._forbidden:
raise RuntimeError("Entity cannot be converted to a corresponding "
"Python representation. Name of property " +
......@@ -362,8 +352,7 @@ class CaosDBPythonEntity(object):
return [att]
def add_parent(self, parent: Union[
CaosDBPythonUnresolvedParent,
CaosDBPythonRecordType]):
CaosDBPythonUnresolvedParent, "CaosDBPythonRecordType"]):
"""
Add a parent to this entity. Either using an unresolved parent or
using a real record type.
......@@ -371,11 +360,10 @@ class CaosDBPythonEntity(object):
if self.has_parent(parent):
raise RuntimeError("Duplicate parent.")
self._parents.add(parent)
self._parents.append(parent)
def has_parent(self, parent: Union[
CaosDBPythonUnresolvedParent,
CaosDBPythonRecordType]):
CaosDBPythonUnresolvedParent, "CaosDBPythonRecordType"]):
"""
Check whether this parent already exists for this entity.
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment