mirror of
https://github.com/yweber/lodel2.git
synced 2026-11-18 00:51:38 +01:00
First implementation of hierarchical data handler
This commit is contained in:
parent
2c47c71116
commit
2b954d4a4d
3 changed files with 31 additions and 9 deletions
5
Makefile
5
Makefile
|
|
@ -1,7 +1,8 @@
|
|||
dyncode_filename='lodel/leapi/dyncode.py'
|
||||
|
||||
all: test doc refresh_dyn
|
||||
all: tests doc dyncode
|
||||
|
||||
# generate doxygen documentation
|
||||
doc: cleandoc
|
||||
doxygen
|
||||
|
||||
|
|
@ -9,9 +10,11 @@ doc: cleandoc
|
|||
em_test:
|
||||
python3 em_test.py
|
||||
|
||||
# generate leapi dynamic code
|
||||
dyncode: clean_dyn em_test
|
||||
python3 scripts/refreshdyn.py examples/em_test.pickle $(dyncode_filename) && echo -e "\n\nCode generated in $(dyncode_filename)"
|
||||
|
||||
# run tests
|
||||
tests:
|
||||
./runtest -v
|
||||
|
||||
|
|
|
|||
|
|
@ -244,7 +244,14 @@ class SingleRef(Reference):
|
|||
# @note SQL implementation could be tricky
|
||||
class MultipleRef(Reference):
|
||||
|
||||
def __init__(self, allowed_classes = None, **kwargs):
|
||||
super().__init__(allowed_classes = allowed_classes, **kwargs)
|
||||
##
|
||||
# @param max_item int | None : indicate the maximum number of item referenced by this field, None mean no limit
|
||||
def __init__(self, max_item = None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
def _check_data_value(self, value):
|
||||
if self.max_item is not None:
|
||||
if self.max_item < len(value):
|
||||
return None, FieldValidationError("To many items")
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ class List(MultipleRef):
|
|||
# @param allowed_classes list | None : list of allowed em classes if None no restriction
|
||||
# @param internal bool
|
||||
# @param kwargs
|
||||
def __init__(self, allowed_classes=None, internal=False, **kwargs):
|
||||
super().__init__(allowed_classes=allowed_classes, internal=internal, **kwargs)
|
||||
def __init__(self, max_length = None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
## @brief Check value
|
||||
# @param value *
|
||||
|
|
@ -20,6 +20,7 @@ class List(MultipleRef):
|
|||
val, expt = super()._check_data_value()
|
||||
if not isinstance(expt, Exception):
|
||||
val = list(val)
|
||||
val, expt = super()._check_data_value(value.values())
|
||||
return val, expt
|
||||
|
||||
|
||||
|
|
@ -30,8 +31,8 @@ class Set(MultipleRef):
|
|||
# @param allowed_classes list | None : list of allowed em classes if None no restriction
|
||||
# @param internal bool : if False, the field is not internal
|
||||
# @param kwargs : Other named arguments
|
||||
def __init__(self, allowed_classes=None, internal=False, **kwargs):
|
||||
super().__init__(allowed_classes=allowed_classes, internal=internal, **kwargs)
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
## @brief Check value
|
||||
# @param value *
|
||||
|
|
@ -40,6 +41,7 @@ class Set(MultipleRef):
|
|||
val, expt = super()._check_data_value()
|
||||
if not isinstance(expt, Exception):
|
||||
val = set(val)
|
||||
val, expt = super()._check_data_value(value.values())
|
||||
return val, expt
|
||||
|
||||
|
||||
|
|
@ -50,8 +52,8 @@ class Map(MultipleRef):
|
|||
# @param allowed_classes list | None : list of allowed em classes if None no restriction
|
||||
# @param internal bool : if False, the field is not internal
|
||||
# @param kwargs : Other named arguments
|
||||
def __init__(self, allowed_classes=None, internal=False, **kwargs):
|
||||
super().__init__(allowed_classes=allowed_classes, internal=internal, **kwargs)
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
## @brief Check value
|
||||
# @param value *
|
||||
|
|
@ -63,3 +65,13 @@ class Map(MultipleRef):
|
|||
return (
|
||||
None if isinstance(expt, Exception) else value,
|
||||
expt)
|
||||
|
||||
## @brief This Reference class is designed to handler hierarchy with some constraint
|
||||
class Hierarch(MultipleRef):
|
||||
|
||||
## @brief Instanciate a data handler handling hierarchical relation with constraints
|
||||
# @param back_reference tuple : Here it is mandatory to have a back ref (like a parent field)
|
||||
# @param max_depth int | None : limit of depth
|
||||
# @param max_childs int | Nine : maximum number of childs by nodes
|
||||
def __init__(self, back_reference, max_depth = None, max_childs = None, **kwargs):
|
||||
super().__init__(back_reference = back_reference)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue