Skip to content

Commit 62a47de

Browse files
committed
[section] Add prop card validation
1 parent 3262605 commit 62a47de

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

odml/section.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ def prop_cardinality(self, new_value):
388388
"""
389389
self._prop_cardinality = format_cardinality(new_value)
390390

391+
# Validate and inform user if the current cardinality is violated
392+
self._properties_cardinality_validation()
393+
391394
def set_properties_cardinality(self, min_val=None, max_val=None):
392395
"""
393396
Sets the Properties cardinality of a Section.
@@ -399,6 +402,17 @@ def set_properties_cardinality(self, min_val=None, max_val=None):
399402
"""
400403
self.prop_cardinality = (min_val, max_val)
401404

405+
def _properties_cardinality_validation(self):
406+
"""
407+
Runs a validation to check whether the properties cardinality
408+
is respected and prints a warning message otherwise.
409+
"""
410+
valid = validation.Validation(self)
411+
# Make sure to display only warnings of the current section
412+
res = [curr for curr in valid.errors if self.id == curr.obj.id]
413+
for err in res:
414+
print("%s: %s" % (err.rank.capitalize(), err.msg))
415+
402416
@inherit_docstring
403417
def get_terminology_equivalent(self):
404418
repo = self.get_repository()

0 commit comments

Comments
 (0)