|
@@ -32,8 +32,8 @@ class EmType(EmComponent):
|
32
|
32
|
('sortcolumn', ftypes.EmField_char)
|
33
|
33
|
]
|
34
|
34
|
|
35
|
|
- def __init__(self, data, components):
|
36
|
|
- super(EmType, self).__init__(data, components)
|
|
35
|
+ def __init__(self, data, model):
|
|
36
|
+ super(EmType, self).__init__(data, model)
|
37
|
37
|
for link in ['fields', 'subordinates']:
|
38
|
38
|
if link in data:
|
39
|
39
|
self._fields[link] = data[link]
|
|
@@ -57,8 +57,13 @@ class EmType(EmComponent):
|
57
|
57
|
## Return the EmClassType of the type
|
58
|
58
|
# @return EditorialModel.classtypes.*
|
59
|
59
|
def classtype(self):
|
60
|
|
- my_class = self.components['uids'][self.class_id]
|
61
|
|
- return getattr(EmClassType, my_class.classtype)
|
|
60
|
+ return getattr(EmClassType, self.em_class.classtype)
|
|
61
|
+
|
|
62
|
+ @property
|
|
63
|
+ ## Return an instance of the class this type belongs to
|
|
64
|
+ # @return EditorialModel.EmClass
|
|
65
|
+ def em_class(self):
|
|
66
|
+ return self.model.component(self.class_id)
|
62
|
67
|
|
63
|
68
|
## @brief Delete an EmType
|
64
|
69
|
# The deletion is only possible if a type is not linked by any EmClass
|
|
@@ -76,33 +81,29 @@ class EmType(EmComponent):
|
76
|
81
|
self.del_superior(sup, nature)
|
77
|
82
|
return super(EmType, self).delete()
|
78
|
83
|
|
79
|
|
- ## Get the list of associated fieldgroups
|
|
84
|
+ ## Get the list of non empty associated fieldgroups
|
80
|
85
|
# @return A list of EmFieldGroup instance
|
81
|
|
- def field_groups(self):
|
82
|
|
- # TODO Réimplémenter
|
83
|
|
- pass
|
84
|
|
- # meta = sqlutils.meta(self.db_engine)
|
85
|
|
- # fg_table = sql.Table(EmFieldGroup.table, meta)
|
86
|
|
- # req = fg_table.select(fg_table.c.uid).where(fg_table.c.class_id == self.class_id)
|
87
|
|
- # conn = self.db_engine.connect()
|
88
|
|
- # res = conn.execute(req)
|
89
|
|
- # rows = res.fetchall()
|
90
|
|
- # conn.close()
|
91
|
|
- #
|
92
|
|
- # return [EmFieldGroup(row['uid']) for row in rows]
|
|
86
|
+ def fieldgroups(self):
|
|
87
|
+ fieldgroups = []
|
|
88
|
+ for fieldgroup in self.em_class.fieldgroups():
|
|
89
|
+ for field in fieldgroup.fields():
|
|
90
|
+ if not field.optional or field.uid in self._fields['fields']:
|
|
91
|
+ fieldgroups.append(fieldgroup)
|
|
92
|
+ break
|
|
93
|
+ return fieldgroups
|
93
|
94
|
|
94
|
95
|
## Get the list of all Emfield possibly associated with this type
|
95
|
96
|
# @return A list of EmField instance
|
96
|
97
|
def all_fields(self):
|
97
|
98
|
res = []
|
98
|
|
- for fieldgroup in self.field_groups():
|
|
99
|
+ for fieldgroup in self.fieldgroups():
|
99
|
100
|
res += fieldgroup.fields()
|
100
|
101
|
return res
|
101
|
102
|
|
102
|
103
|
## Return selected optional field
|
103
|
104
|
# @return A list of EmField instance
|
104
|
105
|
def selected_fields(self):
|
105
|
|
- selected = [ self.components['uids'][field_id] for field_id in self._fields['fields'] ]
|
|
106
|
+ selected = [ self.model.component(field_id) for field_id in self._fields['fields'] ]
|
106
|
107
|
return selected
|
107
|
108
|
|
108
|
109
|
## Return the list of associated fields
|