Skip to content
Snippets Groups Projects
Commit 60361424 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

bugfix: get vocabulary from property_type.vocabulary attribute, not from code...

bugfix: get vocabulary from property_type.vocabulary attribute, not from code of assigned properties
parent 2c02b161
No related branches found
No related tags found
No related merge requests found
...@@ -16,9 +16,13 @@ class PropertyHolder(): ...@@ -16,9 +16,13 @@ class PropertyHolder():
self._property_names[property_name]=prop['propertyType'] self._property_names[property_name]=prop['propertyType']
self._property_names[property_name]['mandatory'] = prop['mandatory'] self._property_names[property_name]['mandatory'] = prop['mandatory']
self._property_names[property_name]['showInEditView'] = prop['showInEditView'] self._property_names[property_name]['showInEditView'] = prop['showInEditView']
if prop['propertyType']['dataType'] == 'CONTROLLEDVOCABULARY':
def _get_terms(self, vocabulary): pt = self._openbis.get_property_type(prop['propertyType']['code'])
return self._openbis.get_terms(vocabulary) # get the vocabulary of a property type.
# In some cases, the «code» of an assigned property is not identical to the «vocabulary» attribute
voc = self._openbis.get_vocabulary(pt.vocabulary)
terms = voc.get_terms()
self._property_names[property_name]['terms'] = terms
def _all_props(self): def _all_props(self):
props = {} props = {}
...@@ -60,7 +64,8 @@ class PropertyHolder(): ...@@ -60,7 +64,8 @@ class PropertyHolder():
if name in self._property_names: if name in self._property_names:
property_type = self._property_names[name] property_type = self._property_names[name]
if property_type['dataType'] == 'CONTROLLEDVOCABULARY': if property_type['dataType'] == 'CONTROLLEDVOCABULARY':
return self._get_terms(property_type['code']) return property_type['terms']
#return self._get_terms(property_type['code'])
else: else:
syntax = { property_type["label"] : property_type["dataType"]} syntax = { property_type["label"] : property_type["dataType"]}
if property_type["dataType"] == "TIMESTAMP": if property_type["dataType"] == "TIMESTAMP":
...@@ -82,11 +87,11 @@ class PropertyHolder(): ...@@ -82,11 +87,11 @@ class PropertyHolder():
property_type = self._property_names[name] property_type = self._property_names[name]
data_type = property_type['dataType'] data_type = property_type['dataType']
if data_type == 'CONTROLLEDVOCABULARY': if data_type == 'CONTROLLEDVOCABULARY':
voc = self._get_terms(property_type['code']) terms = property_type['terms']
value = str(value).upper() value = str(value).upper()
if value not in voc.df['code'].values: if value not in terms.df['code'].values:
raise ValueError("Value for attribute {} must be one of these terms: {}".format( raise ValueError("Value for attribute {} must be one of these terms: {}".format(
name, ", ".join(voc.df['code'].values) name, ", ".join(terms.df['code'].values)
)) ))
elif data_type in ('INTEGER', 'BOOLEAN', 'VARCHAR'): elif data_type in ('INTEGER', 'BOOLEAN', 'VARCHAR'):
if not check_datatype(data_type, value): if not check_datatype(data_type, value):
......
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