|
@@ -15,7 +15,7 @@ import mosql.mysql
|
15
|
15
|
|
16
|
16
|
from DataSource.dummy.leapidatasource import DummyDatasource
|
17
|
17
|
from DataSource.MySQL.common_utils import MySQL
|
18
|
|
-from EditorialModel.classtypes import EmNature, common_fields
|
|
18
|
+from EditorialModel.classtypes import EmNature, common_fields, relations_common_fields
|
19
|
19
|
|
20
|
20
|
|
21
|
21
|
## MySQL DataSource for LeObject
|
|
@@ -175,24 +175,39 @@ class LeDataSourceSQL(DummyDatasource):
|
175
|
175
|
# @todo should work with LeType, LeClass, and Relations
|
176
|
176
|
def insert(self, target_cls, **datas):
|
177
|
177
|
# it is a LeType
|
178
|
|
- if not target_cls.is_letype():
|
179
|
|
- raise AttributeError("'%s' is not a LeType, it is not possible to insert it" % target_cls)
|
|
178
|
+ if target_cls.is_letype():
|
|
179
|
+ main_table = self.datasource_utils.objects_table_name
|
|
180
|
+ main_datas = {'class_id':target_cls._leclass._class_id, 'type_id':target_cls._type_id}
|
|
181
|
+ main_fields = common_fields
|
|
182
|
+ class_table = self.datasource_utils.get_table_name_from_class(target_cls._leclass.__name__)
|
|
183
|
+ # it is a hierarchy
|
|
184
|
+ elif target_cls.is_lehierarch():
|
|
185
|
+ main_table = self.datasource_utils.relations_table_name
|
|
186
|
+ main_datas = {'id_sup':datas['lesup'].lodel_id, 'id_sub':datas['lesub'].lodel_id}
|
|
187
|
+ main_fields = relations_common_fields
|
|
188
|
+ class_table = False
|
|
189
|
+ # it is a relation
|
|
190
|
+ elif target_cls.is_lerel2type():
|
|
191
|
+ print('TODO', datas)
|
|
192
|
+ pass
|
|
193
|
+ else:
|
|
194
|
+ raise AttributeError("'%s' is not a LeType or a LeRelation, it is not possible to insert it" % target_cls)
|
180
|
195
|
|
181
|
196
|
# find main table and main table datas
|
182
|
|
- main_table = self.datasource_utils.objects_table_name
|
183
|
|
- main_datas = {'class_id':target_cls._leclass._class_id, 'type_id':target_cls._type_id}
|
184
|
|
- for main_column_name in common_fields:
|
|
197
|
+ for main_column_name in main_fields:
|
185
|
198
|
if main_column_name in datas:
|
186
|
199
|
main_datas[main_column_name] = datas[main_column_name]
|
187
|
200
|
del(datas[main_column_name])
|
188
|
201
|
|
189
|
|
- cur = self.datasource_utils.query(self.connection, insert(main_table, main_datas))
|
|
202
|
+ sql = insert(main_table, main_datas)
|
|
203
|
+ #print (sql)
|
|
204
|
+ cur = self.datasource_utils.query(self.connection, sql)
|
190
|
205
|
lodel_id = cur.lastrowid
|
191
|
206
|
|
192
|
|
- # insert in class_table
|
193
|
|
- datas[self.datasource_utils.field_lodel_id] = lodel_id
|
194
|
|
- class_table = self.datasource_utils.get_table_name_from_class(target_cls._leclass.__name__)
|
195
|
|
- self.datasource_utils.query(self.connection, insert(class_table, datas))
|
|
207
|
+ if class_table:
|
|
208
|
+ # insert in class_table
|
|
209
|
+ datas[self.datasource_utils.field_lodel_id] = lodel_id
|
|
210
|
+ self.datasource_utils.query(self.connection, insert(class_table, datas))
|
196
|
211
|
|
197
|
212
|
return lodel_id
|
198
|
213
|
|