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.

reference.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. from lodel.leapi.datahandlers.field_data_handler import FieldDataHandler
  3. from lodel.editorial_model.components import EmClass
  4. class Reference(FieldDataHandler):
  5. ## @brief Instanciation
  6. # @param allowed bool
  7. # @param internal bool : if False, the field is not internal
  8. # @param **kwargs : other arguments
  9. def __init__(self, allowed=True, internal=False, **kwargs):
  10. self.allowed = allowed
  11. self.internal = internal
  12. if not self.is_ref_valid():
  13. raise ValueError("The target of the reference is not valid")
  14. super().__init__(internal=self.internal, **kwargs)
  15. ## @brief gets the target of the reference
  16. def get_relateds(self):
  17. return self._refs
  18. ## @brief checks if the target is valid
  19. def is_ref_valid(self):
  20. relateds = self.get_relateds()
  21. if not isinstance(relateds, self._refs_class):
  22. return False
  23. if isinstance(relateds, EmClass):
  24. relateds = [relateds]
  25. for related in relateds:
  26. if not isinstance(related, EmClass):
  27. return False
  28. return True