|
@@ -51,7 +51,7 @@ class LeDataSourceSQL(DummyDatasource):
|
51
|
51
|
fields = [(main_table, common_fields)]
|
52
|
52
|
|
53
|
53
|
# it is a LeType or a LeClass, query on main table left join class table on lodel_id
|
54
|
|
- elif hasattr(target_cls, '_leclass') or hasattr(target_cls, '_class_id'):
|
|
54
|
+ elif target_cls.is_letype() or target_cls.is_leclass():
|
55
|
55
|
# find main table and main table datas
|
56
|
56
|
main_table = self.datasource_utils.objects_table_name
|
57
|
57
|
main_class = target_cls._leclass if hasattr(target_cls, '_leclass') else target_cls
|
|
@@ -170,22 +170,24 @@ class LeDataSourceSQL(DummyDatasource):
|
170
|
170
|
# @todo should work with LeType, LeClass, and Relations
|
171
|
171
|
def insert(self, target_cls, **datas):
|
172
|
172
|
# it is a LeType
|
173
|
|
- if (hasattr(target_cls, '_leclass')):
|
174
|
|
- # find main table and main table datas
|
175
|
|
- main_table = self.datasource_utils.objects_table_name
|
176
|
|
- main_datas = {'class_id':target_cls._leclass._class_id, 'type_id':target_cls._type_id}
|
177
|
|
- for main_column_name in common_fields:
|
178
|
|
- if main_column_name in datas:
|
179
|
|
- main_datas[main_column_name] = datas[main_column_name]
|
180
|
|
- unset(datas[main_column_name])
|
181
|
|
-
|
182
|
|
- cur = self.datasource_utils.query(self.connection, insert(main_table, main_datas))
|
183
|
|
- lodel_id = cur.lastrowid
|
184
|
|
-
|
185
|
|
- # insert in class_table
|
186
|
|
- datas[self.datasource_utils.field_lodel_id] = lodel_id
|
187
|
|
- class_table = self.datasource_utils.get_table_name_from_class(target_cls._leclass.__name__)
|
188
|
|
- self.datasource_utils.query(self.connection, insert(class_table, datas))
|
|
173
|
+ if not target_cls.is_letype():
|
|
174
|
+ raise AttributeError("'%s' is not a LeType, it is not possible to insert it" % target_cls)
|
|
175
|
+
|
|
176
|
+ # find main table and main table datas
|
|
177
|
+ main_table = self.datasource_utils.objects_table_name
|
|
178
|
+ main_datas = {'class_id':target_cls._leclass._class_id, 'type_id':target_cls._type_id}
|
|
179
|
+ for main_column_name in common_fields:
|
|
180
|
+ if main_column_name in datas:
|
|
181
|
+ main_datas[main_column_name] = datas[main_column_name]
|
|
182
|
+ unset(datas[main_column_name])
|
|
183
|
+
|
|
184
|
+ cur = self.datasource_utils.query(self.connection, insert(main_table, main_datas))
|
|
185
|
+ lodel_id = cur.lastrowid
|
|
186
|
+
|
|
187
|
+ # insert in class_table
|
|
188
|
+ datas[self.datasource_utils.field_lodel_id] = lodel_id
|
|
189
|
+ class_table = self.datasource_utils.get_table_name_from_class(target_cls._leclass.__name__)
|
|
190
|
+ self.datasource_utils.query(self.connection, insert(class_table, datas))
|
189
|
191
|
|
190
|
192
|
return lodel_id
|
191
|
193
|
|