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.

fields.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #-*- coding: utf-8 -*-
  2. from EditorialModel.components import EmComponent
  3. from EditorialModel.exceptions import EmComponentCheckError
  4. import EditorialModel
  5. ## EmField (Class)
  6. #
  7. # Represents one data for a lodel2 document
  8. class EmField(EmComponent):
  9. ranked_in = 'fieldgroup_id'
  10. ## Instanciate a new EmField
  11. # @todo define and test type for icon and fieldtype
  12. def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_to_type_id=None, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None):
  13. self.fieldgroup_id = fieldgroup_id
  14. self.check_type('fieldgroup_id', int)
  15. self.fieldtype = fieldtype
  16. self.optional = optional
  17. self.check_type('optional', bool)
  18. self.internal = internal
  19. self.check_type('internal', bool)
  20. self.rel_to_type_id = rel_to_type_id
  21. self.check_type('rel_to_type_id', (int, type(None)))
  22. self.rel_field_id = rel_field_id
  23. self.check_type('rel_field_id', (int, type(None)))
  24. self.icon = icon
  25. super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
  26. ## Check if the EmField is valid
  27. # @return True if valid False if not
  28. def check(self):
  29. super(EmField, self).check()
  30. em_fieldgroup = self.model.component(self.fieldgroup_id)
  31. if not em_fieldgroup:
  32. raise EmComponentCheckError("fieldgroup_id contains a non existing uid : '%d'" % self.fieldgroup_id)
  33. if not isinstance(em_fieldgroup, EditorialModel.fieldgroups.EmFieldGroup):
  34. raise EmComponentCheckError("fieldgroup_id contains an uid from a component that is not an EmFieldGroup but a %s" % str(type(em_fieldgroup)))
  35. ## @brief Delete a field if it's not linked
  36. # @return bool : True if deleted False if deletion aborded
  37. # @todo Check if unconditionnal deletion is correct
  38. def delete_check(self):
  39. return True