|
@@ -19,6 +19,7 @@ from EditorialModel.classtypes import EmNature
|
19
|
19
|
from EditorialModel.fieldtypes.generic import MultiValueFieldType
|
20
|
20
|
|
21
|
21
|
from Lodel.settings import Settings
|
|
22
|
+from .fieldtypes import fieldtype_cast
|
22
|
23
|
|
23
|
24
|
## MySQL DataSource for LeObject
|
24
|
25
|
class LeDataSourceSQL(DummyDatasource):
|
|
@@ -143,7 +144,8 @@ class LeDataSourceSQL(DummyDatasource):
|
143
|
144
|
joins.append(rel_join)
|
144
|
145
|
|
145
|
146
|
# prefix filters'' column names, and prepare dict for mosql where {(fieldname, op): value}
|
146
|
|
- wheres = {(utils.find_prefix(name, fields), op):value for name,op,value in filters}
|
|
147
|
+ # TODO: this will not work with special filters
|
|
148
|
+ wheres = {(utils.find_prefix(name, fields), op):fieldtype_cast(target_cls.fieldtypes()[name], value) for name,op,value in filters}
|
147
|
149
|
query = select(main_table, select=prefixed_field_list, where=wheres, joins=joins, **kwargs)
|
148
|
150
|
|
149
|
151
|
# Executing the query
|
|
@@ -228,6 +230,8 @@ class LeDataSourceSQL(DummyDatasource):
|
228
|
230
|
def update(self, target_cls, filters, rel_filters, **datas):
|
229
|
231
|
class_table = False
|
230
|
232
|
|
|
233
|
+ datas = { fname: fieldtype_cast(target_cls.fieldtypes()[fname], datas[fname]) for fname in datas }
|
|
234
|
+
|
231
|
235
|
# it is a LeType
|
232
|
236
|
if target_cls.is_letype():
|
233
|
237
|
# find main table and main table datas
|
|
@@ -300,6 +304,9 @@ class LeDataSourceSQL(DummyDatasource):
|
300
|
304
|
else:
|
301
|
305
|
raise AttributeError("'%s' is not a LeType nor a LeRelation, it's impossible to insert it" % target_cls)
|
302
|
306
|
|
|
307
|
+ # cast datas
|
|
308
|
+ datas = { fname: fieldtype_cast(target_cls.fieldtypes()[fname], datas[fname]) for fname in datas }
|
|
309
|
+
|
303
|
310
|
# extract main table datas from datas
|
304
|
311
|
for main_column_name in main_fields:
|
305
|
312
|
if main_column_name in datas:
|