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.

classes.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. ## @file classes.py
  3. # @see EditorialModel::classes::EmClass
  4. from EditorialModel.components import EmComponent
  5. import EditorialModel.fieldtypes as ftypes
  6. import EditorialModel
  7. ## @brief Manipulate Classes of the Editorial Model
  8. # Create classes of object.
  9. # @see EmClass, EmType, EditorialModel.fieldgroups.EmFieldGroup, EmField
  10. # @todo sortcolumn handling
  11. class EmClass(EmComponent):
  12. ranked_in = 'classtype'
  13. ## @brief Specific EmClass fields
  14. # @see EditorialModel::components::EmComponent::_fields
  15. _fields = [
  16. ('classtype', ftypes.EmField_char),
  17. ('icon', ftypes.EmField_icon),
  18. ('sortcolumn', ftypes.EmField_char)
  19. ]
  20. ## Check if the EmComponent is valid
  21. # @return True if valid False if not
  22. def check(self):
  23. super(EmClass, self).check()
  24. return True
  25. ## @brief Delete a class if it's ''empty''
  26. # If a class has no fieldgroups delete it
  27. # @return bool : True if deleted False if deletion aborded
  28. def delete(self):
  29. for emtype in self.model.components(EmType):
  30. if emtype.class_id == self.uid:
  31. return False
  32. for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
  33. if fieldgroup.class_id == self.uid:
  34. return False
  35. return True
  36. ## Retrieve list of the field_groups of this class
  37. # @return A list of fieldgroups instance
  38. def fieldgroups(self):
  39. ret = []
  40. for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
  41. if fieldgroup.class_id == self.uid:
  42. ret.append(fieldgroup)
  43. return ret
  44. ## Retrieve list of fields
  45. # @return fields [EmField]:
  46. def fields(self):
  47. fieldgroups = self.fieldgroups()
  48. fields = []
  49. for fieldgroup in fieldgroups:
  50. fields += fieldgroup.fields()
  51. return fields
  52. ## Retrieve list of type of this class
  53. # @return types [EmType]:
  54. def types(self):
  55. ret = []
  56. for emtype in self.components(EmType):
  57. if emtype.class_id == self.uid:
  58. ret.append(emtype)
  59. return ret
  60. ## Add a new EmType that can ben linked to this class
  61. # @param em_type EmType: type to link
  62. # @return success bool: done or not
  63. def link_type(self, em_type):
  64. pass
  65. ## Retrieve list of EmType that are linked to this class
  66. # @return types [EmType]:
  67. def linked_types(self):
  68. pass