|
18 | 18 | from .property import BaseProperty
|
19 | 19 | # it MUST however not be used to create any Property objects
|
20 | 20 | from .tools.doc_inherit import inherit_docstring, allow_inherit_docstring
|
| 21 | +from .util import format_cardinality |
21 | 22 |
|
22 | 23 |
|
23 | 24 | @allow_inherit_docstring
|
@@ -85,12 +86,16 @@ def __init__(self, name=None, type="n.s.", parent=None,
|
85 | 86 | self._repository = repository
|
86 | 87 | self._link = link
|
87 | 88 | self._include = include
|
88 |
| - self._prop_cardinality = prop_cardinality |
| 89 | + self._prop_cardinality = None |
89 | 90 |
|
90 | 91 | # this may fire a change event, so have the section setup then
|
91 | 92 | self.type = type
|
92 | 93 | self.parent = parent
|
93 | 94 |
|
| 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 | + |
94 | 99 | for err in validation.Validation(self).errors:
|
95 | 100 | if err.is_error:
|
96 | 101 | use_name = err.obj.name if err.obj.id != err.obj.name else None
|
@@ -355,6 +360,45 @@ def get_repository(self):
|
355 | 360 | def repository(self, url):
|
356 | 361 | base.Sectionable.repository.fset(self, url)
|
357 | 362 |
|
| 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 | + |
358 | 402 | @inherit_docstring
|
359 | 403 | def get_terminology_equivalent(self):
|
360 | 404 | repo = self.get_repository()
|
|
0 commit comments