|
@@ -10,6 +10,7 @@ import importlib
|
10
|
10
|
import re
|
11
|
11
|
|
12
|
12
|
from EditorialModel.fieldtypes.generic import DatasConstructor
|
|
13
|
+from Lodel.hooks import LodelHook
|
13
|
14
|
|
14
|
15
|
REL_SUP = 0
|
15
|
16
|
REL_SUB = 1
|
|
@@ -279,6 +280,15 @@ class _LeCrud(object):
|
279
|
280
|
# @todo better error handling
|
280
|
281
|
# @todo for check_data_consistency, datas must be populated to make update safe !
|
281
|
282
|
def update(self, datas=None):
|
|
283
|
+ kwargs = locals()
|
|
284
|
+ del(kwargs['self'])
|
|
285
|
+ kwargs = LodelHook.call_hook('leapi_update_pre', self, kwargs)
|
|
286
|
+ ret = self.__update_unsafe(**kwargs)
|
|
287
|
+ return ret
|
|
288
|
+
|
|
289
|
+ ## @brief Unsafe, without hooks version of insert method
|
|
290
|
+ # @see _LeCrud.update()
|
|
291
|
+ def __update_unsafe(self, datas=None):
|
282
|
292
|
if not self.is_complete():
|
283
|
293
|
self.populate()
|
284
|
294
|
warnings.warn("\nThis object %s is not complete and has been populated when update was called. This is very unsafe\n" % self)
|
|
@@ -297,7 +307,9 @@ class _LeCrud(object):
|
297
|
307
|
# @return True if success
|
298
|
308
|
# @todo better error handling
|
299
|
309
|
def delete(self):
|
|
310
|
+ LodelHook.call_hook('leapi_delete_pre', self, None)
|
300
|
311
|
self._datasource.delete(self.__class__, self.uidget())
|
|
312
|
+ return LodelHook.call_hook('leapi_delete_post', self, None)
|
301
|
313
|
|
302
|
314
|
## @brief Check that datas are valid for this type
|
303
|
315
|
# @param datas dict : key == field name value are field values
|
|
@@ -358,6 +370,17 @@ class _LeCrud(object):
|
358
|
370
|
# @todo think about LeObject and LeClass instanciation (partial instanciation, etc)
|
359
|
371
|
@classmethod
|
360
|
372
|
def get(cls, query_filters, field_list=None, order=None, group=None, limit=None, offset=0, instanciate=True):
|
|
373
|
+ kwargs = locals()
|
|
374
|
+ del(kwargs['cls'])
|
|
375
|
+ kwargs = LodelHook.call_hook('leapi_get_pre', cls, kwargs)
|
|
376
|
+ ret = cls.__get_unsafe(**kwargs)
|
|
377
|
+ return LodelHook.call_hook('leapi_get_post', cls, ret)
|
|
378
|
+
|
|
379
|
+ ## @brief Unsafe, without hooks version of get() method
|
|
380
|
+ # @see _LeCrud.get()
|
|
381
|
+ @classmethod
|
|
382
|
+ def __get_unsafe(cls, query_filters, field_list=None, order=None, group=None, limit=None, offset=0, instanciate=True):
|
|
383
|
+
|
361
|
384
|
if field_list is None or len(field_list) == 0:
|
362
|
385
|
#default field_list
|
363
|
386
|
field_list = cls.fieldlist()
|
|
@@ -409,6 +432,16 @@ class _LeCrud(object):
|
409
|
432
|
# @return A new id if success else False
|
410
|
433
|
@classmethod
|
411
|
434
|
def insert(cls, datas, classname=None):
|
|
435
|
+ kwargs = locals()
|
|
436
|
+ del(kwargs['cls'])
|
|
437
|
+ kwargs = LodelHook.call_hook('leapi_insert_pre', cls, kwargs)
|
|
438
|
+ ret = cls.__insert_unsafe(**kwargs)
|
|
439
|
+ return LodelHook.call_hook('leapi_insert_post', cls, ret)
|
|
440
|
+
|
|
441
|
+ ## @brief Unsafe, without hooks version of insert() method
|
|
442
|
+ # @see _LeCrud.insert()
|
|
443
|
+ @classmethod
|
|
444
|
+ def __insert_unsafe(cls, datas, classname=None):
|
412
|
445
|
callcls = cls if classname is None else cls.name2class(classname)
|
413
|
446
|
if not callcls:
|
414
|
447
|
raise LeApiErrors("Error when inserting",{'error':ValueError("The class '%s' was not found"%classname)})
|