Skip to content
Snippets Groups Projects
Commit 8909f28d authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

add conversion

parent a108328b
No related branches found
No related tags found
2 merge requests!22Release 0.3,!14F fix list
Pipeline #10433 passed
...@@ -192,7 +192,7 @@ class Parser(object): ...@@ -192,7 +192,7 @@ class Parser(object):
self._add_entity_to_model(name, entity) self._add_entity_to_model(name, entity)
# initialize recordtypes # initialize recordtypes
self._set_recordtypes() self._set_recordtypes()
self._check_datatypes() self._check_and_convert_datatypes()
for name, entity in ymlmodel.items(): for name, entity in ymlmodel.items():
self._treat_entity(name, entity, line=ymlmodel["__line__"]) self._treat_entity(name, entity, line=ymlmodel["__line__"])
...@@ -384,7 +384,7 @@ class Parser(object): ...@@ -384,7 +384,7 @@ class Parser(object):
raise e raise e
self.treated.append(name) self.treated.append(name)
def _check_datatypes(self): def _check_and_convert_datatypes(self):
""" checks if datatype is valid. """ checks if datatype is valid.
datatype of properties is simply initialized with string. Here, we datatype of properties is simply initialized with string. Here, we
iterate over properties and check whether it is a base datatype of a iterate over properties and check whether it is a base datatype of a
...@@ -395,13 +395,19 @@ class Parser(object): ...@@ -395,13 +395,19 @@ class Parser(object):
if isinstance(value, db.Property): if isinstance(value, db.Property):
dtype = value.datatype dtype = value.datatype
is_list = False
if _get_listdatatype(value.datatype) is not None: if _get_listdatatype(value.datatype) is not None:
dtype = _get_listdatatype(value.datatype) dtype = _get_listdatatype(value.datatype)
is_list = True
if dtype in self.model: if dtype in self.model:
if is_list:
value.datatype = db.LIST(self.model[dtype])
else:
value.datatype = self.model[dtype]
continue continue
# get the datatype
if dtype in [db.DOUBLE, if dtype in [db.DOUBLE,
db.REFERENCE, db.REFERENCE,
...@@ -411,7 +417,13 @@ class Parser(object): ...@@ -411,7 +417,13 @@ class Parser(object):
db.FILE, db.FILE,
db.BOOLEAN]: db.BOOLEAN]:
if is_list:
value.datatype = db.LIST(db.__getattribute__(dtype))
else:
value.datatype = db.__getattribute__(dtype)
continue continue
raise ValueError("Unknown Datatype.") raise ValueError("Unknown Datatype.")
def _set_recordtypes(self): def _set_recordtypes(self):
......
...@@ -200,9 +200,14 @@ RT1: ...@@ -200,9 +200,14 @@ RT1:
recommended_properties: recommended_properties:
a: a:
datatype: LIST(RT2) datatype: LIST(RT2)
b:
datatype: LIST(TEXT)
RT2: RT2:
""" """
parse_model_from_yaml(to_file(string)) model = parse_model_from_yaml(to_file(string))
self.assertTrue(isinstance(model['b'], db.Property))
self.assertEqual(model['b'].datatype, db.LIST(db.TEXT))
# This failed for an older version of caosdb-models # This failed for an older version of caosdb-models
string_list = """ string_list = """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment