Skip to content

Commit 3262605

Browse files
committed
[section] Add prop card accessor methods
1 parent 41acc15 commit 3262605

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

odml/section.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .property import BaseProperty
1919
# it MUST however not be used to create any Property objects
2020
from .tools.doc_inherit import inherit_docstring, allow_inherit_docstring
21+
from .util import format_cardinality
2122

2223

2324
@allow_inherit_docstring
@@ -85,12 +86,16 @@ def __init__(self, name=None, type="n.s.", parent=None,
8586
self._repository = repository
8687
self._link = link
8788
self._include = include
88-
self._prop_cardinality = prop_cardinality
89+
self._prop_cardinality = None
8990

9091
# this may fire a change event, so have the section setup then
9192
self.type = type
9293
self.parent = parent
9394

95+
# This might lead to a validation warning, since properties are set
96+
# at a later point in time.
97+
self.prop_cardinality = prop_cardinality
98+
9499
for err in validation.Validation(self).errors:
95100
if err.is_error:
96101
use_name = err.obj.name if err.obj.id != err.obj.name else None
@@ -355,6 +360,45 @@ def get_repository(self):
355360
def repository(self, url):
356361
base.Sectionable.repository.fset(self, url)
357362

363+
@property
364+
def prop_cardinality(self):
365+
"""
366+
The Property cardinality of a Section. It defines how many Properties
367+
are minimally required and how many Properties should be maximally
368+
stored. Use the 'set_properties_cardinality' method to set.
369+
"""
370+
return self._prop_cardinality
371+
372+
@prop_cardinality.setter
373+
def prop_cardinality(self, new_value):
374+
"""
375+
Sets the Properties cardinality of a Section.
376+
377+
The following cardinality cases are supported:
378+
(n, n) - default, no restriction
379+
(d, n) - minimally d entries, no maximum
380+
(n, d) - maximally d entries, no minimum
381+
(d, d) - minimally d entries, maximally d entries
382+
383+
Only positive integers are supported. 'None' is used to denote
384+
no restrictions on a maximum or minimum.
385+
386+
:param new_value: Can be either 'None', a positive integer, which will set
387+
the maximum or an integer 2-tuple of the format '(min, max)'.
388+
"""
389+
self._prop_cardinality = format_cardinality(new_value)
390+
391+
def set_properties_cardinality(self, min_val=None, max_val=None):
392+
"""
393+
Sets the Properties cardinality of a Section.
394+
395+
:param min_val: Required minimal number of values elements. None denotes
396+
no restrictions on values elements minimum. Default is None.
397+
:param max_val: Allowed maximal number of values elements. None denotes
398+
no restrictions on values elements maximum. Default is None.
399+
"""
400+
self.prop_cardinality = (min_val, max_val)
401+
358402
@inherit_docstring
359403
def get_terminology_equivalent(self):
360404
repo = self.get_repository()

0 commit comments

Comments
 (0)