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):
self._add_entity_to_model(name, entity)
# initialize recordtypes
self._set_recordtypes()
self._check_datatypes()
self._check_and_convert_datatypes()
for name, entity in ymlmodel.items():
self._treat_entity(name, entity, line=ymlmodel["__line__"])
......@@ -384,7 +384,7 @@ class Parser(object):
raise e
self.treated.append(name)
def _check_datatypes(self):
def _check_and_convert_datatypes(self):
""" checks if datatype is valid.
datatype of properties is simply initialized with string. Here, we
iterate over properties and check whether it is a base datatype of a
......@@ -395,13 +395,19 @@ class Parser(object):
if isinstance(value, db.Property):
dtype = value.datatype
is_list = False
if _get_listdatatype(value.datatype) is not None:
dtype = _get_listdatatype(value.datatype)
is_list = True
if dtype in self.model:
if is_list:
value.datatype = db.LIST(self.model[dtype])
else:
value.datatype = self.model[dtype]
continue
# get the datatype
if dtype in [db.DOUBLE,
db.REFERENCE,
......@@ -411,7 +417,13 @@ class Parser(object):
db.FILE,
db.BOOLEAN]:
if is_list:
value.datatype = db.LIST(db.__getattribute__(dtype))
else:
value.datatype = db.__getattribute__(dtype)
continue
raise ValueError("Unknown Datatype.")
def _set_recordtypes(self):
......
......@@ -200,9 +200,14 @@ RT1:
recommended_properties:
a:
datatype: LIST(RT2)
b:
datatype: LIST(TEXT)
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
string_list = """
......
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