|
@@ -234,7 +234,7 @@ class _LeCrud(object):
|
234
|
234
|
# @param field_list None|list : List of fieldname to fetch. If None fetch all the missing datas
|
235
|
235
|
# @todo Add checks to forbid the use of this method on abtract classes (LeObject, LeClass, LeType, LeRel2Type, LeRelation etc...)
|
236
|
236
|
def populate(self, field_list=None):
|
237
|
|
- if not self._instanciation_complete:
|
|
237
|
+ if not self.is_complete():
|
238
|
238
|
if field_list == None:
|
239
|
239
|
field_list = [ fname for fname in self._fields if not hasattr(self, fname) ]
|
240
|
240
|
filters = [self._id_filter()]
|
|
@@ -255,7 +255,7 @@ class _LeCrud(object):
|
255
|
255
|
# the correct class
|
256
|
256
|
# @return Corresponding populated LeObject
|
257
|
257
|
def get_instance(self):
|
258
|
|
- if self._instanciation_complete:
|
|
258
|
+ if self.is_complete():
|
259
|
259
|
return self
|
260
|
260
|
uid_fname = self.uidname()
|
261
|
261
|
qfilter = '{uid_fname} = {uid}'.format(uid_fname = uid_fname, uid = getattr(self, uid_fname))
|
|
@@ -265,7 +265,11 @@ class _LeCrud(object):
|
265
|
265
|
# @param datas dict : If None use instance attributes to update de DB
|
266
|
266
|
# @return True if success
|
267
|
267
|
# @todo better error handling
|
268
|
|
- def update(self, datas = None):
|
|
268
|
+ # @todo for check_data_consistency, datas must be populated to make update safe !
|
|
269
|
+ def update(self, datas=None):
|
|
270
|
+ if not self.is_complete():
|
|
271
|
+ self.populate()
|
|
272
|
+ warnings.warn("\nThis object %s is not complete and has been populated. This is very unsafe\n" % self)
|
269
|
273
|
datas = self.datas(internal=False) if datas is None else datas
|
270
|
274
|
upd_datas = self.prepare_datas(datas, complete = False, allow_internal = False)
|
271
|
275
|
filters = [self._id_filter()]
|
|
@@ -400,7 +404,7 @@ class _LeCrud(object):
|
400
|
404
|
# @param datas dict : The value of object we want to insert
|
401
|
405
|
# @return A new id if success else False
|
402
|
406
|
@classmethod
|
403
|
|
- def insert(cls, datas, classname = None):
|
|
407
|
+ def insert(cls, datas, classname=None):
|
404
|
408
|
callcls = cls if classname is None else cls.name2class(classname)
|
405
|
409
|
if not callcls:
|
406
|
410
|
raise LeApiErrors("Error when inserting",[ValueError("The class '%s' was not found"%classname)])
|
|
@@ -416,16 +420,18 @@ class _LeCrud(object):
|
416
|
420
|
# @param datas dict : {fieldname : fieldvalue, ...}
|
417
|
421
|
# @param complete bool : If True you MUST give all the datas
|
418
|
422
|
# @param allow_internal : Wether or not interal fields are expected in datas
|
419
|
|
- # @return Datas ready for use
|
|
423
|
+ # @return Datas ready for use
|
|
424
|
+ # @todo: complete is very unsafe, find a way to get rid of it
|
420
|
425
|
@classmethod
|
421
|
|
- def prepare_datas(cls, datas, complete = False, allow_internal = True):
|
|
426
|
+ def prepare_datas(cls, datas, complete=False, allow_internal=True):
|
422
|
427
|
if not complete:
|
423
|
|
- warnings.warn("\nActual implementation can make datas construction and consitency checks fails when datas are not complete\n")
|
|
428
|
+ warnings.warn("\nActual implementation can make datas construction and consitency unsafe when datas are not complete\n")
|
424
|
429
|
ret_datas = cls.check_datas_value(datas, complete, allow_internal)
|
425
|
430
|
if isinstance(ret_datas, Exception):
|
426
|
431
|
raise ret_datas
|
427
|
|
- ret_datas = cls._construct_datas(ret_datas)
|
428
|
|
- cls._check_datas_consistency(ret_datas)
|
|
432
|
+ if complete:
|
|
433
|
+ ret_datas = cls._construct_datas(ret_datas)
|
|
434
|
+ cls._check_datas_consistency(ret_datas)
|
429
|
435
|
return ret_datas
|
430
|
436
|
|
431
|
437
|
#-###################-#
|