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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. ## @file classes.py
  3. # @see EditorialModel::classes::EmClass
  4. from EditorialModel.components import EmComponent
  5. from EditorialModel.classtypes import EmClassType
  6. from EditorialModel.types import EmType
  7. #from EditorialModel.exceptions import *
  8. #import EditorialModel.fieldtypes as ftypes
  9. import EditorialModel
  10. ## @brief Manipulate Classes of the Editorial Model
  11. # Create classes of object.
  12. # @see EmClass, EmType, EditorialModel.fieldgroups.EmFieldGroup, EmField
  13. # @todo sortcolumn handling
  14. class EmClass(EmComponent):
  15. ranked_in = 'classtype'
  16. ## EmClass instanciation
  17. # @todo Classtype initialisation and test is not good EmClassType should give an answer or something like that
  18. # @todo defines types check for icon and sortcolumn
  19. def __init__(self, model, uid, name, classtype, icon='0', sortcolumn='rank', string=None, help_text=None, date_update=None, date_create=None, rank=None):
  20. try:
  21. getattr(EmClassType, classtype)
  22. except AttributeError:
  23. raise AttributeError("Unknown classtype '%s'" % classtype)
  24. self.classtype = classtype
  25. self.icon = icon
  26. self.sortcolumn = sortcolumn # 'rank'
  27. super(EmClass, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
  28. ## Check if the EmComponent is valid
  29. # @throw EmComponentCheckError if fails
  30. def check(self):
  31. super(EmClass, self).check()
  32. ## @brief Delete a class if it's ''empty''
  33. # If a class has no fieldgroups delete it
  34. # @return bool : True if deleted False if deletion aborded
  35. def delete_check(self):
  36. for emtype in self.model.components(EmType):
  37. if emtype.class_id == self.uid:
  38. return False
  39. for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
  40. if fieldgroup.class_id == self.uid:
  41. return False
  42. return True
  43. ## Retrieve list of the field_groups of this class
  44. # @return A list of fieldgroups instance
  45. def fieldgroups(self):
  46. ret = []
  47. for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
  48. if fieldgroup.class_id == self.uid:
  49. ret.append(fieldgroup)
  50. return ret
  51. ## Retrieve list of fields
  52. # @return fields [EmField]:
  53. def fields(self):
  54. fieldgroups = self.fieldgroups()
  55. fields = []
  56. for fieldgroup in fieldgroups:
  57. fields += fieldgroup.fields()
  58. return fields
  59. ## Retrieve list of type of this class
  60. # @return types [EmType]:
  61. def types(self):
  62. ret = []
  63. for emtype in self.model.components(EmType):
  64. if emtype.class_id == self.uid:
  65. ret.append(emtype)
  66. return ret
  67. ## Add a new EmType that can ben linked to this class
  68. # @param em_type EmType: type to link
  69. # @return success bool: done or not
  70. def link_type(self, em_type):
  71. pass
  72. ## Retrieve list of EmType that are linked to this class
  73. # @return types [EmType]:
  74. def linked_types(self):
  75. pass