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.

emuid.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #-*- coding: utf-8 -*-
  2. import leapi.lecrud as lecrud
  3. import leapi.letype as letype
  4. from .generic import FieldTypeError
  5. from . import integer
  6. class EmFieldType(integer.EmFieldType):
  7. help = 'Fieldtypes designed to handle editorial model UID for LeObjects'
  8. _construct_datas_deps = []
  9. def __init__(self, is_id_class, **kwargs):
  10. self._is_id_class = is_id_class
  11. kwargs['internal'] = 'automatic'
  12. super().__init__(is_id_class = is_id_class, **kwargs)
  13. def _check_data_value(self, value):
  14. return (value, None)
  15. def construct_data(self, lec, fname, datas, cur_value):
  16. ret = None
  17. if self.is_id_class:
  18. if lec.implements_leclass():
  19. ret = lec._class_id
  20. else:
  21. if lec.implements_letype():
  22. ret = lec._type_id
  23. return ret
  24. def check_data_consistency(self, lec, fname, datas):
  25. if datas[fname] != (lec._class_id if self.is_id_class else lec._type_id):
  26. return FieldTypeError("Given Editorial model uid doesn't fit with given LeObject")