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.

lerelation.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #-*- coding: utf-8 -*-
  2. import copy
  3. import EditorialModel.fieldtypes.leo as ft_leo
  4. from . import lecrud
  5. ## @brief Main class for relations
  6. class _LeRelation(lecrud._LeCrud):
  7. ## @brief Handles the superior
  8. _lesup_fieldtype = {'lesup': ft_leo.EmFieldType(True)}
  9. ## @brief Handles the subordinate
  10. _lesub_fieldtype = {'lesub': ft_leo.EmFieldType(False) }
  11. ## @brief Stores the list of fieldtypes that are common to all relations
  12. _rel_fieldtypes = dict()
  13. ## @brief Stores the list of fieldtypes handling relations attributes
  14. _rel_attr_fieldtypes = dict()
  15. def __init__(self, rel_id, **kwargs):
  16. pass
  17. @classmethod
  18. def sup_filter(self, leo):
  19. if isinstance(leo, _LeObject):
  20. return ('lesup', '=', leo)
  21. @classmethod
  22. def sub_filter(self, leo):
  23. if isinstance(leo, _LeObject):
  24. return ('lesub', '=', leo)
  25. @classmethod
  26. def fieldtypes(cls):
  27. rel_ft = dict()
  28. rel_ft.update(cls._lesup_fieldtype)
  29. rel_ft.update(cls._lesub_fieldtype)
  30. rel_ft.update(cls._rel_fieldtypes)
  31. rel_ft.update(cls._rel_attr_fieldtypes)
  32. return rel_ft
  33. @classmethod
  34. def _prepare_relational_fields(cls, field):
  35. return lecrud.LeApiQueryError("Relational field '%s' given but %s doesn't is not a LeObject"%(field,cls.__name__))
  36. ## @brief Abstract class to handle hierarchy relations
  37. class _LeHierarch(_LeRelation):
  38. def __init__(self, rel_id):
  39. pass
  40. ## @brief Abstract class to handle rel2type relations
  41. class _LeRel2Type(_LeRelation):
  42. pass