No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dict.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from lodel.leapi.datahandlers.reference import Reference
  3. from lodel.editorial_model.components import EmClass
  4. class DataHandler(Reference):
  5. ## @brief instanciates a dict reference
  6. # @param allowed_classes list | None : list of allowed em classes if None no restriction
  7. # @param internal bool : if False, the field is not internal
  8. # @param kwargs : Other named arguments
  9. def __init__(self, allowed_classes = None, internal=False, **kwargs):
  10. super().__init__(allowed_classes=allowed_classes, internal=internal, **kwargs)
  11. ## @brief checks if the given target is valid
  12. # @return bool
  13. def _check_data_value(self, value):
  14. relateds = self.get_relateds()
  15. if not isinstance(relateds, self._refs_class):
  16. return
  17. for related in relateds.values():
  18. if not isinstance(related, EmClass):
  19. return False
  20. return True
  21. ## @brief adds a referenced element
  22. # @param ref_name str : key of the item in the reference dict
  23. # @param emclass EmClass
  24. # @return bool
  25. def add_ref(self, ref_name, emclass):
  26. if isinstance(emclass, EmClass) and isinstance(ref_name, str):
  27. self._refs[ref_name] = emclass
  28. return True
  29. return False