Skip to content

Commit 7569aed

Browse files
committed
[section] Add sec card validation
Also adds a set Section section cardinality convenience method.
1 parent 4f31158 commit 7569aed

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

odml/section.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,31 @@ def sec_cardinality(self, new_value):
394394
"""
395395
self._sec_cardinality = format_cardinality(new_value)
396396

397+
# Validate and inform user if the current cardinality is violated
398+
self._sections_cardinality_validation()
399+
400+
def set_sections_cardinality(self, min_val=None, max_val=None):
401+
"""
402+
Sets the Sections cardinality of a Section.
403+
404+
:param min_val: Required minimal number of values elements. None denotes
405+
no restrictions on values elements minimum. Default is None.
406+
:param max_val: Allowed maximal number of values elements. None denotes
407+
no restrictions on values elements maximum. Default is None.
408+
"""
409+
self.sec_cardinality = (min_val, max_val)
410+
411+
def _sections_cardinality_validation(self):
412+
"""
413+
Runs a validation to check whether the sections cardinality
414+
is respected and prints a warning message otherwise.
415+
"""
416+
valid = validation.Validation(self)
417+
# Make sure to display only warnings of the current section
418+
res = [curr for curr in valid.errors if self.id == curr.obj.id]
419+
for err in res:
420+
print("%s: %s" % (err.rank.capitalize(), err.msg))
421+
397422
@property
398423
def prop_cardinality(self):
399424
"""

0 commit comments

Comments
 (0)