12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- # -*- coding: utf-8 -*-
-
- ## @file classes.py
- # @see EditorialModel::classes::EmClass
-
- from EditorialModel.components import EmComponent
- import EditorialModel.fieldtypes as ftypes
- import EditorialModel
-
- ## @brief Manipulate Classes of the Editorial Model
- # Create classes of object.
- # @see EmClass, EmType, EmFieldGroup, EmField
- # @todo sortcolumn handling
- class EmClass(EmComponent):
-
- table = 'em_class'
- ranked_in = 'classtype'
-
- ## @brief Specific EmClass fields
- # @see EditorialModel::components::EmComponent::_fields
- _fields = [
- ('classtype', ftypes.EmField_char),
- ('icon', ftypes.EmField_icon),
- ('sortcolumn', ftypes.EmField_char)
- ]
-
- ## Create a new class
- # @param name str: name of the new class
- # @param class_type EmClasstype: type of the class
- # @return an EmClass instance
- # @throw EmComponentExistError if an EmClass with this name and a different classtype exists
- @classmethod
- def create(cls, name, classtype, icon=None, sortcolumn='rank', **em_component_args):
- result = super(EmClass, cls).create(name=name, classtype=classtype, icon=icon, sortcolumn=sortcolumn, **em_component_args)
- return result
-
- @property
- ## @brief Return the table name used to stores data on this class
- def class_table_name(self):
- return self.name
-
- ## @brief Delete a class if it's ''empty''
- # If a class has no fieldgroups delete it
- # @return bool : True if deleted False if deletion aborded
- def delete(self):
- for uid, emtype in self.components[Model.name_from_emclass(EmType)].items:
- if emtype.class_id == self.uid:
- return False
- for uid, fieldgroup in self.components[Model.name_from_emclass(EmFieldGroup)].items():
- if fieldgroup.class_id == self.uid:
- return False
- return super(EmClass, self).delete()
-
- ## Retrieve list of the field_groups of this class
- # @return A list of fieldgroups instance
- def fieldgroups(self):
- ret = []
- for uid,fieldgroup in self.components[Model.name_from_emclass(EmFieldGroup)].items():
- if fieldgroup.class_id == self.uid:
- ret.append(fieldgroup)
- return ret
-
- ## Retrieve list of fields
- # @return fields [EmField]:
- def fields(self):
- fieldgroups = self.fieldgroups()
- fields = []
- for fieldgroup in fieldgroups:
- fields += fieldgroup.fields()
- return fields
-
- ## Retrieve list of type of this class
- # @return types [EmType]:
- def types(self):
- ret = []
- for uid, emtype in self.components[Model.name_from_emclass(EmType)].items:
- if emtype.class_id == self.uid:
- ret.append(emtype)
- return ret
-
- ## Add a new EmType that can ben linked to this class
- # @param em_type EmType: type to link
- # @return success bool: done or not
- def link_type(self, em_type):
- pass
-
- ## Retrieve list of EmType that are linked to this class
- # @return types [EmType]:
- def linked_types(self):
- pass
|