|
@@ -5,7 +5,7 @@
|
5
|
5
|
|
6
|
6
|
from EditorialModel.components import EmComponent
|
7
|
7
|
import EditorialModel.fieldtypes as ftypes
|
8
|
|
-
|
|
8
|
+import EditorialModel
|
9
|
9
|
|
10
|
10
|
## @brief Manipulate Classes of the Editorial Model
|
11
|
11
|
# Create classes of object.
|
|
@@ -24,16 +24,68 @@ class EmClass(EmComponent):
|
24
|
24
|
('sortcolumn', ftypes.EmField_char)
|
25
|
25
|
]
|
26
|
26
|
|
|
27
|
+ ## Create a new class
|
|
28
|
+ # @param name str: name of the new class
|
|
29
|
+ # @param class_type EmClasstype: type of the class
|
|
30
|
+ # @return an EmClass instance
|
|
31
|
+ # @throw EmComponentExistError if an EmClass with this name and a different classtype exists
|
|
32
|
+ @classmethod
|
|
33
|
+ def create(cls, name, classtype, icon=None, sortcolumn='rank', **em_component_args):
|
|
34
|
+ pass
|
|
35
|
+ # return cls._create_db(name=name, classtype=classtype['name'], icon=icon, sortcolumn=sortcolumn, **em_component_args)
|
|
36
|
+
|
|
37
|
+ # @classmethod
|
|
38
|
+ # def _create_db(cls, name, classtype, icon, sortcolumn, **em_component_args):
|
|
39
|
+ # result = super(Em, cls).create(name=name, classtype=classtype, icon=icon, sortcolumn=sortcolumn, **em_component_args)
|
|
40
|
+ #
|
|
41
|
+ # dbe = result.db_engine
|
|
42
|
+ # conn= dbe.connect()
|
|
43
|
+ #
|
|
44
|
+ # meta = sql.MetaData()
|
|
45
|
+ # emclasstable = sql.Table(result.class_table_name, meta, sql.Column('uid', sql.VARCHAR(50), primary_key=True))
|
|
46
|
+ # emclasstable.create(conn)
|
|
47
|
+ # conn.close()
|
|
48
|
+ # return result
|
|
49
|
+
|
27
|
50
|
@property
|
28
|
51
|
## @brief Return the table name used to stores data on this class
|
29
|
52
|
def class_table_name(self):
|
30
|
53
|
return self.name
|
31
|
54
|
|
|
55
|
+ ## @brief Delete a class if it's ''empty''
|
|
56
|
+ # If a class has no fieldgroups delete it
|
|
57
|
+ # @return bool : True if deleted False if deletion aborded
|
|
58
|
+ def delete(self):
|
|
59
|
+ pass
|
|
60
|
+ # fieldgroups = self.fieldgroups()
|
|
61
|
+ # if len(fieldgroups) > 0:
|
|
62
|
+ # return False
|
|
63
|
+ #
|
|
64
|
+ # dbe = self.db_engine
|
|
65
|
+ # meta = sqlutils.meta(dbe)
|
|
66
|
+ # Here we have to give a connection
|
|
67
|
+ # class_table = sql.Table(self.name, meta)
|
|
68
|
+ # meta.drop_all(tables=[class_table], bind=dbe)
|
|
69
|
+ # return super(EmClass, self).delete()
|
32
|
70
|
|
33
|
71
|
## Retrieve list of the field_groups of this class
|
34
|
72
|
# @return A list of fieldgroups instance
|
35
|
73
|
def fieldgroups(self):
|
36
|
|
- pass
|
|
74
|
+ records = self._fieldgroups_db() # TODO Modifier l'appel
|
|
75
|
+ fieldgroups = [EditorialModel.fieldgroups.EmFieldGroup(int(record.uid)) for record in records]
|
|
76
|
+
|
|
77
|
+ return fieldgroups
|
|
78
|
+
|
|
79
|
+ ## Isolate SQL for EmClass::fieldgroups
|
|
80
|
+ # @return An array of dict (sqlalchemy fetchall)
|
|
81
|
+ # def _fieldgroups_db(self):
|
|
82
|
+ # dbe = self.db_engine
|
|
83
|
+ # emfg = sql.Table(EditorialModel.fieldgroups.EmFieldGroup.table, sqlutils.meta(dbe))
|
|
84
|
+ # req = emfg.select().where(emfg.c.class_id == self.uid)
|
|
85
|
+ #
|
|
86
|
+ # conn = dbe.connect()
|
|
87
|
+ # res = conn.execute(req)
|
|
88
|
+ # return res.fetchall()
|
37
|
89
|
|
38
|
90
|
## Retrieve list of fields
|
39
|
91
|
# @return fields [EmField]:
|
|
@@ -48,15 +100,53 @@ class EmClass(EmComponent):
|
48
|
100
|
# @return types [EmType]:
|
49
|
101
|
def types(self):
|
50
|
102
|
pass
|
|
103
|
+ records = self._types_db() # TODO Modifier l'appel
|
|
104
|
+ types = [EditorialModel.types.EmType(int(record.uid)) for record in records]
|
|
105
|
+
|
|
106
|
+ return types
|
|
107
|
+
|
|
108
|
+ ## Isolate SQL for EmCLass::types
|
|
109
|
+ # @return An array of dict (sqlalchemy fetchall)
|
|
110
|
+ # def _types_db(self):
|
|
111
|
+ # dbe = self.db_engine
|
|
112
|
+ # emtype = sql.Table(EditorialModel.types.EmType.table, sqlutils.meta(dbe))
|
|
113
|
+ # req = emtype.select().where(emtype.c.class_id == self.uid)
|
|
114
|
+ # conn = dbe.connect()
|
|
115
|
+ # res = conn.execute(req)
|
|
116
|
+ # return res.fetchall()
|
51
|
117
|
|
52
|
118
|
## Add a new EmType that can ben linked to this class
|
53
|
119
|
# @param em_type EmType: type to link
|
54
|
120
|
# @return success bool: done or not
|
55
|
121
|
def link_type(self, em_type):
|
56
|
|
- pass
|
|
122
|
+ table_name = self.name + '_' + em_type.name
|
|
123
|
+ self._link_type_db(table_name) # TODO Modifier l'appel
|
|
124
|
+
|
|
125
|
+ return True
|
|
126
|
+
|
|
127
|
+ # def _link_type_db(self, table_name):
|
|
128
|
+ # Create a new table storing additionnal fields for the relation between the linked type and this EmClass
|
|
129
|
+ # conn = self.db_engine.connect()
|
|
130
|
+ # meta = sql.MetaData()
|
|
131
|
+ # emlinketable = sql.Table(table_name, meta, sql.Column('uid', sql.VARCHAR(50), primary_key=True))
|
|
132
|
+ # emlinketable.create(conn)
|
|
133
|
+ # conn.close()
|
57
|
134
|
|
58
|
135
|
|
59
|
136
|
## Retrieve list of EmType that are linked to this class
|
60
|
137
|
# @return types [EmType]:
|
61
|
138
|
def linked_types(self):
|
62
|
|
- pass
|
|
139
|
+ return self._linked_types_db() # TODO Modifier l'appel
|
|
140
|
+
|
|
141
|
+ # def _linked_types_db(self):
|
|
142
|
+ # dbe = self.db_engine
|
|
143
|
+ # meta = sql.MetaData()
|
|
144
|
+ # meta.reflect(dbe)
|
|
145
|
+ #
|
|
146
|
+ # linked_types = []
|
|
147
|
+ # for table in meta.tables.values():
|
|
148
|
+ # table_name_elements = table.name.split('_')
|
|
149
|
+ # if len(table_name_elements) == 2:
|
|
150
|
+ # linked_types.append(EditorialModel.types.EmType(table_name_elements[1]))
|
|
151
|
+ #
|
|
152
|
+ # return linked_types
|