Browse Source

Supressed _fields from EmComponent and transforming the EmComponent in a standart object with standarts attributes

Yann Weber 9 years ago
parent
commit
b6ef37752f

+ 14
- 1
EditorialModel/backend/json_backend.py View File

@@ -9,6 +9,13 @@ import json
9 9
 ## Manages a Json file based backend structure
10 10
 class EmBackendJson(object):
11 11
 
12
+    cast_methods = {
13
+        'uid' : int,
14
+        'rank' : int,
15
+        'class_id' : int,
16
+        'fieldgroup_id' : int
17
+    }
18
+
12 19
     ## Constructor
13 20
     #
14 21
     # @param json_file str: path to the json_file used as data source
@@ -22,5 +29,11 @@ class EmBackendJson(object):
22 29
     def load(self):
23 30
         data = {}
24 31
         for index, component in self.data.items():
25
-            data[int(index)] = component
32
+            attributes = {}
33
+            for attr_name, attr_value in component.items():
34
+                if attr_name in EmBackendJson.cast_methods:
35
+                    attributes[attr_name] = EmBackendJson.cast_methods[attr_name](attr_value)
36
+                else:
37
+                    attributes[attr_name] = attr_value
38
+            data[int(index)] = attributes
26 39
         return data

+ 9
- 0
EditorialModel/classes.py View File

@@ -23,7 +23,16 @@ class EmClass(EmComponent):
23 23
         ('icon', ftypes.EmField_icon),
24 24
         ('sortcolumn', ftypes.EmField_char)
25 25
     ]
26
+
27
+    ## EmClass instanciation
28
+    def __init__(self, model, uid, name, classtype, icon = '0', sortcolumn = 'rank', string = None, help_text = None, date_update = None, date_create = None, rank = None):
29
+        self.classtype = classtype
30
+        self.icon = icon
31
+        self.sortcolumn = 'rank'
32
+        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)
33
+        pass
26 34
     
35
+
27 36
     ## Check if the EmComponent is valid
28 37
     # @return True if valid False if not
29 38
     def check(self):

+ 18
- 85
EditorialModel/components.py View File

@@ -7,6 +7,7 @@ import datetime
7 7
 
8 8
 import logging
9 9
 import EditorialModel.fieldtypes as ftypes
10
+from Lodel.utils.mlstring import MlString
10 11
 from collections import OrderedDict
11 12
 
12 13
 logger = logging.getLogger('Lodel2.EditorialModel')
@@ -22,79 +23,22 @@ class EmComponent(object):
22 23
     ## Used by EmComponent::modify_rank
23 24
     ranked_in = None
24 25
 
25
-    ## Read only properties
26
-    _ro_properties = ['date_update', 'date_create', 'uid', 'rank', 'deleted']
27
-
28
-    ## @brief List fields name and fieldtype
29
-    #
30
-    # This is a list that describe database fields common for each EmComponent child classes.
31
-    # A database field is defined here by a tuple(name, type) with name a string and type an EditorialModel.fieldtypes.EmFieldType
32
-    # @warning The EmFieldType in second position in the tuples must be a class type and not a class instance !!!
33
-    # @see EditorialModel::classes::EmClass::_fields EditorialModel::fieldgroups::EmFieldGroup::_fields EditorialModel::types::EmType::_fields EditorialModel::fields::EmField::_fields
34
-    _fields = [
35
-        ('uid', ftypes.EmField_integer),
36
-        ('name', ftypes.EmField_char),
37
-        ('rank', ftypes.EmField_integer),
38
-        ('date_update', ftypes.EmField_date),
39
-        ('date_create', ftypes.EmField_date),
40
-        ('string', ftypes.EmField_mlstring),
41
-        ('help', ftypes.EmField_mlstring)
42
-    ]
43
-
44
-    ## Instaciate an EmComponent
45
-    # @param id_or_name int|str: name or id of the object
46
-    # @throw TypeError if id_or_name is not an integer nor a string
47
-    # @throw NotImplementedError if called with EmComponent
48
-    def __init__(self, data, model):
26
+    def __init__(self, model, uid, name, string = None, help_text = None, date_update = None, date_create = None, rank = None):
49 27
         if type(self) == EmComponent:
50
-            raise NotImplementedError('Abstract class')
51
-
52
-        ## @brief An OrderedDict storing fields name and values
53
-        # Values are handled by EditorialModel::fieldtypes::EmFieldType
54
-        # @warning \ref _fields instance property is not the same than EmComponent::_fields class property. In the instance property the EditorialModel::fieldtypes::EmFieldType are instanciated to be able to handle datas
55
-        # @see EmComponent::_fields EditorialModel::fieldtypes::EmFieldType
56
-        self._fields = OrderedDict([(name, ftype()) for (name, ftype) in (EmComponent._fields + self.__class__._fields)])
28
+           raise NotImplementedError('Abstract class')
29
+ 
57 30
         self.model = model
31
+        self.uid = uid
32
+        self.name = name
33
+        self.string = MlString() if string is None else string
34
+        self.help_text = MlString() if help_text is None else help_text
35
+        self.date_update = datetime.datetime.now() if date_update is None else date_update #WARNING timezone !
36
+        self.date_create = datetime.datetime.now() if date_create is None else date_create #WARNING timezone !
37
+
38
+        #Handling specials ranks for component creation
39
+        self.rank = rank
40
+        pass
58 41
 
59
-        for name, value in data.items():
60
-            if name in self._fields:
61
-                self._fields[name].from_string(value)
62
-
63
-
64
-    ## @brief Access an attribute of an EmComponent
65
-    # This method is overloads the default __getattr__ to search in EmComponents::_fields . If there is an EditorialModel::EmField with a corresponding name in the component
66
-    # it returns its value.
67
-    # @param name str: The attribute name
68
-    # @throw AttributeError if attribute don't exists
69
-    # @see EditorialModel::EmField::value
70
-    def __getattr__(self, name):
71
-        if name != '_fields' and name in self._fields:
72
-            return self._fields[name].value
73
-        else:
74
-            return super(EmComponent, self).__getattribute__(name)
75
-
76
-    ## @brief Access an EmComponent attribute
77
-    # This function overload the default __getattribute__ in order to check if the EmComponent was deleted.
78
-    # @param name str: The attribute name
79
-    # @throw EmComponentNotExistError if the component was deleted
80
-    def __getattribute__(self, name):
81
-        if super(EmComponent, self).__getattribute__('deleted'):
82
-            raise EmComponentNotExistError("This " + super(EmComponent, self).__getattribute__('__class__').__name__ + " has been deleted")
83
-        res = super(EmComponent, self).__getattribute(name)
84
-        return res
85
-
86
-    ## Set the value of an EmComponent attribute
87
-    # @param name str: The propertie name
88
-    # @param value *: The value
89
-    def __setattr__(self, name, value):
90
-        if name in self.__class__._ro_properties:
91
-            raise TypeError("Propertie '" + name + "' is readonly")
92
-
93
-        if name != '_fields' and hasattr(self, '_fields') and name in object.__getattribute__(self, '_fields'):
94
-            self._fields[name].from_python(value)
95
-        else:
96
-            object.__setattr__(self, name, value)
97
-    
98 42
     ## @brief Hash function that allows to compare two EmComponent
99 43
     # @return EmComponent+ClassName+uid
100 44
     def __hash__(self):
@@ -105,17 +49,6 @@ class EmComponent(object):
105 49
     def __eq__(self, other):
106 50
         return self.__class__ == other.__class__ and self.uid == other.uid
107 51
 
108
-    ## Set all fields
109
-    def populate(self):
110
-        records = []  # TODO
111
-
112
-        for record in records:
113
-            for keys in self._fields.keys():
114
-                if keys in record:
115
-                    self._fields[keys].from_string(record[keys])
116
-
117
-        super(EmComponent, self).__setattr__('deleted', False)
118
-
119 52
     ## Check if the EmComponent is valid
120 53
     # This function has to check that rank are correct and continuous other checks are made in childs classes
121 54
     # @warning Hardcoded minimum rank
@@ -125,7 +58,7 @@ class EmComponent(object):
125 58
         if self.get_max_rank() > len(self.same_rank_group()):
126 59
             #Non continuous ranks
127 60
             for i, component in enumerate(self.same_rank_group()):
128
-                component._fields['rank'].value = i + 1
61
+                component.rank = i + 1
129 62
         # No need to sort again here
130 63
         return True
131 64
 
@@ -133,7 +66,7 @@ class EmComponent(object):
133 66
     # @return A positive integer or -1 if no components
134 67
     def get_max_rank(self):
135 68
         components = self.same_rank_group()
136
-        return -1 if len(components) == 0 else components[-1].rank
69
+        return 1 if len(components) == 0 else components[-1].rank
137 70
 
138 71
     ## Return an array of instances that are concerned by the same rank
139 72
     # @return An array of instances that are concerned by the same rank
@@ -167,9 +100,9 @@ class EmComponent(object):
167 100
         limits.sort()
168 101
 
169 102
         for component in [ c for c in self.same_rank_group() if c.rank >= limits[0] and c.rank <= limits[1] ] :
170
-            component._fields['rank'].value = component.rank + ( -1 if mod > 0 else 1 )
103
+            component.rank = component.rank + ( -1 if mod > 0 else 1 )
171 104
 
172
-        self._fields['rank'].value = new_rank
105
+        self.rank = new_rank
173 106
 
174 107
         self.model.sort_components(self.__class__)
175 108
 

+ 5
- 2
EditorialModel/fieldgroups.py View File

@@ -13,8 +13,11 @@ class EmFieldGroup(EmComponent):
13 13
 
14 14
     ranked_in = 'class_id'
15 15
 
16
-    ## List of fields
17
-    _fields = [('class_id', ftypes.EmField_integer)]
16
+    ## EmFieldGroup instanciation
17
+    def __init__(self, model, uid, name, class_id, string = None, help_text = None, date_update = None, date_create = None, rank = None):
18
+        self.class_id = class_id
19
+        super(EmFieldGroup, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
20
+        pass
18 21
 
19 22
     ## Check if the EmFieldGroup is valid
20 23
     # @return True if valid False if not

+ 9
- 12
EditorialModel/fields.py View File

@@ -9,20 +9,17 @@ from EditorialModel.fieldtypes import EmField_boolean, EmField_char, EmField_int
9 9
 # Represents one data for a lodel2 document
10 10
 class EmField(EmComponent):
11 11
 
12
-    table = 'em_field'
13 12
     ranked_in = 'fieldgroup_id'
14
-    _fields = [
15
-        ('fieldtype', EmField_char),
16
-        ('fieldgroup_id', EmField_integer),
17
-        ('rel_to_type_id', EmField_integer),
18
-        ('rel_field_id', EmField_integer),
19
-        ('optional', EmField_boolean),
20
-        ('internal', EmField_boolean),
21
-        ('icon', EmField_icon)
22
-    ]
23 13
 
24
-    def __init__(self, datas, model):
25
-        super(EmField, self).__init__(datas, model)
14
+    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):
15
+        self.fieldgroup_id = fieldgroup_id
16
+        self.fieldtype = fieldtype
17
+        self.optional = optional
18
+        self.internal = internal
19
+        self.rel_to_type_id = rel_to_type_id
20
+        self.rel_field_id = rel_field_id
21
+        self.icon = icon
22
+        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 23
 
27 24
     ## Check if the EmField is valid
28 25
     # @return True if valid False if not

+ 14
- 28
EditorialModel/model.py View File

@@ -50,14 +50,16 @@ class Model(object):
50 50
     # @todo Change the thrown exception when a components check fails
51 51
     # @throw ValueError When a component class don't exists
52 52
     def load(self):
53
-        data = self.backend.load()
54
-        for uid, component in data.items():
55
-            cls_name = component['component']
53
+        datas = self.backend.load()
54
+        for uid, kwargs in datas.items():
55
+            #Store and delete the EmComponent class name from datas
56
+            cls_name = kwargs['component']
57
+            del kwargs['component']
56 58
             cls = self.emclass_from_name(cls_name)
57 59
             if cls:
58
-                component['uid'] = uid
60
+                kwargs['uid'] = uid
59 61
                 # create a dict for the component and one indexed by uids, store instanciated component in it
60
-                self._components['uids'][uid] = cls(component, self)
62
+                self._components['uids'][uid] = cls(self, **kwargs)
61 63
                 self._components[cls_name].append(self._components['uids'][uid])
62 64
             else:
63 65
                 raise ValueError("Unknow EmComponent class : '" + cls_name + "'")
@@ -114,36 +116,20 @@ class Model(object):
114 116
         
115 117
         em_obj = self.emclass_from_name(component_type)
116 118
 
117
-        datas['uid'] = self.new_uid()
118
-        em_component = em_obj(datas, self)
119
-
120
-        rank = None
119
+        rank = 'last'
121 120
         if 'rank' in datas:
122 121
             rank = datas['rank']
123
-        datas['rank'] = None
122
+            del datas['rank']
124 123
 
124
+        datas['uid'] = self.new_uid()
125
+        em_component = em_obj(self, **datas)
125 126
 
126 127
         self._components['uids'][em_component.uid] = em_component
127 128
         self._components[self.name_from_emclass(em_component.__class__)].append(em_component)
128 129
 
129
-
130
-        create_fails = None
131
-
132
-        if rank is None or rank == 'last':
133
-            em_component.rank = em_component.get_max_rank()
134
-        elif datas['rank'] == 'first':
135
-            em_component.set_rank(1)
136
-        elif isinstance(rank, int):
137
-            em_component.set_rank(rank)
138
-        else:
139
-            create_fails = ValueError("Invalid rank : '"+str(datas['rank'])+"'")
140
-            self.delete(em_component.uid)
141
-
142
-        if not em_component.check():
143
-            create_fails = RuntimeError("After creation the component self check fails")
144
-        
145
-        if not create_fails is None:
146
-            raise create_fails
130
+        em_component.rank = em_component.get_max_rank()
131
+        if rank != 'last':
132
+            em_component.set_rank( 1 if rank == 'first' else rank)
147 133
 
148 134
         return em_component
149 135
 

+ 17
- 17
EditorialModel/test/me.json View File

@@ -1,53 +1,53 @@
1 1
 {
2 2
   "1" : {
3
-    "component":"EmClass", "name":"textes", "string":"{\"fre\":\"Texte\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
3
+    "component":"EmClass", "name":"textes", "string":"{\"fre\":\"Texte\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
4 4
   },
5 5
   "2" : {
6
-    "component":"EmClass", "name":"personnes", "string":"{\"fre\":\"Personnes\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "classtype":"person", "icon":"0", "sortcolumn":"rank"
6
+    "component":"EmClass", "name":"personnes", "string":"{\"fre\":\"Personnes\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "classtype":"person", "icon":"0", "sortcolumn":"rank"
7 7
   },
8 8
   "3" : {
9
-    "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1"
9
+    "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1"
10 10
   },
11 11
   "4" : {
12
-    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
12
+    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
13 13
   },
14 14
   "5" : {
15
-    "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "selected_fields":[7]
15
+    "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "selected_fields":[7]
16 16
   },
17 17
   "6" : {
18
-    "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "selected_fields":[10]
18
+    "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "selected_fields":[10]
19 19
   },
20 20
   "7" : {
21
-    "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
21
+    "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
22 22
   },
23 23
   "8" : {
24
-    "component":"EmFieldGroup", "name":"civilité", "string":"{\"fre\":\"Civilité\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2"
24
+    "component":"EmFieldGroup", "name":"civilité", "string":"{\"fre\":\"Civilité\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2"
25 25
   },
26 26
   "9" : {
27
-    "component":"EmField", "name":"nom", "string":"{\"fre\":\"Nom\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"8", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
27
+    "component":"EmField", "name":"nom", "string":"{\"fre\":\"Nom\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"8", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
28 28
   },
29 29
   "10" : {
30
-    "component":"EmField", "name":"prenom", "string":"{\"fre\":\"Preom\"}", "help":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"8", "rel_to_type_id":"", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
30
+    "component":"EmField", "name":"prenom", "string":"{\"fre\":\"Preom\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"8", "rel_to_type_id":"", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
31 31
   },
32 32
   "11" : {
33
-    "component":"EmField", "name":"auteur", "string":"{\"fre\":\"Auteur\"}", "help":"{}", "rank":"3", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"6", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
33
+    "component":"EmField", "name":"auteur", "string":"{\"fre\":\"Auteur\"}", "help_text":"{}", "rank":"3", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"6", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
34 34
   },
35 35
   "12" : {
36
-    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help":"{}", "rank":"4", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"", "rel_field_id":"11", "optional":"0", "internal":"", "icon":"0"
36
+    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help_text":"{}", "rank":"4", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"", "rel_field_id":"11", "optional":"0", "internal":"", "icon":"0"
37 37
   },
38 38
   "13" : {
39
-    "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
39
+    "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
40 40
   },
41 41
   "14" : {
42
-    "component":"EmType", "name":"rubrique", "string":"{\"fre\":\"Rubrique\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13", "icon":"0", "sortcolumn":"rank", "subordinates":[["parent",5], ["parent",14]]
42
+    "component":"EmType", "name":"rubrique", "string":"{\"fre\":\"Rubrique\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13", "icon":"0", "sortcolumn":"rank", "subordinates":[["parent",5], ["parent",14]]
43 43
   },
44 44
   "15" : {
45
-    "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"
45
+    "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"
46 46
   },
47 47
   "16" : {
48
-    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"15", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
48
+    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"15", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
49 49
   },
50 50
   "17" : {
51
-    "component":"EmFieldGroup", "name":"gens", "string":"{\"fre\":\"Gens\"}", "help":"{}", "rank":"2", "date_update":"", "date_create":"", "class_id":"1"
51
+    "component":"EmFieldGroup", "name":"gens", "string":"{\"fre\":\"Gens\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "class_id":"1"
52 52
   }
53 53
 }

+ 8
- 17
EditorialModel/types.py View File

@@ -20,25 +20,16 @@ import EditorialModel.classes
20 20
 # @see EditorialModel::components::EmComponent
21 21
 # @todo sortcolumn handling
22 22
 class EmType(EmComponent):
23
-    table = 'em_type'
24
-    table_hierarchy = 'em_type_hierarchy'
25 23
     ranked_in = 'class_id'
26 24
 
27
-    ## @brief Specific EmClass fields
28
-    # @see EditorialModel::components::EmComponent::_fields
29
-    _fields = [
30
-        ('class_id', ftypes.EmField_integer),
31
-        ('icon', ftypes.EmField_icon),
32
-        ('sortcolumn', ftypes.EmField_char)
33
-    ]
34
-
35
-    def __init__(self, data, model):
36
-        super(EmType, self).__init__(data, model)
37
-        for link in ['selected_fields', 'subordinates']:
38
-            if link in data:
39
-                self._fields[link] = data[link]
40
-            else:
41
-                self._fields[link] = []
25
+    def __init__(self, model, uid, name, class_id, selected_fields = [], subordinates = [], icon = '0', sortcolumn = 'rank', string = None, help_text = None, date_update = None, date_create = None, rank = None):
26
+        self.class_id = class_id
27
+        self.selected_fields = selected_fields
28
+        self.subordinates = subordinates
29
+        self.icon = icon
30
+        self.sortcolumn = sortcolumn
31
+        super(EmType, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
32
+        pass
42 33
 
43 34
     @classmethod
44 35
     ## Create a new EmType and instanciate it

Loading…
Cancel
Save