|
@@ -25,20 +25,22 @@ class EmType(EmComponent):
|
25
|
25
|
## Instanciate a new EmType
|
26
|
26
|
# @todo define and check types for icon and sortcolumn
|
27
|
27
|
# @todo better check self.subordinates
|
28
|
|
- 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):
|
|
28
|
+ def __init__(self, model, uid, name, class_id, fields_list = [], subordinates_list = {}, icon = '0', sortcolumn = 'rank', string = None, help_text = None, date_update = None, date_create = None, rank = None):
|
29
|
29
|
self.class_id = class_id
|
30
|
30
|
self.check_type('class_id', int)
|
31
|
|
- self.selected_fields = selected_fields
|
32
|
|
- self.check_type('selected_fields', list)
|
33
|
|
- for l_uid in self.selected_fields:
|
|
31
|
+ self.fields_list = fields_list
|
|
32
|
+ self.check_type('fields_list', list)
|
|
33
|
+ for l_uid in self.fields_list:
|
34
|
34
|
if not isinstance(l_uid, int):
|
35
|
|
- raise AttributeError("Excepted selected_fields to be a list of integers, but found a +"+str(type(l_uid))+" in it")
|
|
35
|
+ raise AttributeError("Excepted fields_list to be a list of integers, but found a +"+str(type(l_uid))+" in it")
|
36
|
36
|
|
37
|
|
- self.subordinates = subordinates
|
38
|
|
- self.check_type('subordinates', list)
|
39
|
|
- for l_uid in self.subordinates:
|
40
|
|
- if not isinstance(l_uid[0], str) or not isinstance(l_uid[1], int):
|
41
|
|
- raise AttributeError("Excepted selected_fields to be a list of nature,int !")
|
|
37
|
+ self.subordinates_list = subordinates_list
|
|
38
|
+ print(subordinates_list)
|
|
39
|
+ self.check_type('subordinates_list', dict)
|
|
40
|
+ for nature, uids in self.subordinates_list.items():
|
|
41
|
+ for uid in uids:
|
|
42
|
+ if not isinstance(uid, int):
|
|
43
|
+ raise AttributeError("Excepted subordinates of nature %s to be a list int !" % nature)
|
42
|
44
|
|
43
|
45
|
self.icon = icon
|
44
|
46
|
self.sortcolumn = sortcolumn
|
|
@@ -83,8 +85,7 @@ class EmType(EmComponent):
|
83
|
85
|
# @todo Check if the type is not linked by any EmClass
|
84
|
86
|
# @todo Check if there is no other ''non-deletion'' conditions
|
85
|
87
|
def delete(self):
|
86
|
|
- subs = self.subordinates()
|
87
|
|
- if sum([len(subs[subnat]) for subnat in subs]) > 0:
|
|
88
|
+ if sum(self.subordinates_list) > 0:
|
88
|
89
|
return False
|
89
|
90
|
#Delete all relation with superiors
|
90
|
91
|
for nature, sups in self.superiors().items():
|
|
@@ -103,9 +104,9 @@ class EmType(EmComponent):
|
103
|
104
|
|
104
|
105
|
## Return selected optional field
|
105
|
106
|
# @return A list of EmField instance
|
106
|
|
- #def selected_fields(self):
|
107
|
|
- #selected = [self.model.component(field_id) for field_id in self._fields['selected_fields']]
|
108
|
|
- #return selected
|
|
107
|
+ def selected_fields(self):
|
|
108
|
+ selected = [self.model.component(field_id) for field_id in self.fields_list]
|
|
109
|
+ return selected
|
109
|
110
|
|
110
|
111
|
## Return the list of associated fields
|
111
|
112
|
# @return A list of EmField instance
|