1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-10-31 03:29:03 +01:00

Adds LeQuery.is_exist function to test the existence of an LeObject instance

This commit is contained in:
prieto 2017-01-26 16:04:41 +01:00
commit 54b1521d09
2 changed files with 22 additions and 1 deletions

View file

@ -13,6 +13,17 @@ LodelContext.expose_modules(globals(), {
'lodel.plugin.hooks': ['LodelHook'],
'lodel.logger': ['logger']})
##@brief Tool to check if a target_class's object exists and is stored
#@param target_class : class where the object is supposed to be
#@param uid : a unique id in target_class
#@returns true if an object with unique id uid exists in target_class, false if not
def is_exist(target_class, uid):
from .leobject import LeObject
if not inspect.isclass(target_class) or not issubclass(target_class, LeObject):
raise TypeError("target class has to be a child class of LeObject but %s was given"% target_class)
datasource = target_class._ro_datasource
return datasource.is_exist(target_class,uid)
##@todo check datas when running query
class LeQuery(object):

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
object# -*- coding: utf-8 -*-
import re
import warnings
@ -874,3 +874,13 @@ field/operator couple in a query. We will keep only the first one")
#with sets
datas[dname] = list(datas[dname])
return datas
##@brief Tool to check if a record with unique id uid is set in the target_class representation
#@param target_class : class to check in
#@param uid : a unique id in target_class
#@returns true if a record with unique id uid exists in the target_class representation, false if not
def is_exist(self, target_class, uid):
# retrouver la table qui correspond à target_class
# vérifier qu'il existe, ou pas, un enregistrement contenant uid
result = self.select(self, target_class, [target_class.uid_fieldname], filters = [(target_class.uid_fieldname, '=', uid)])
return len(result) == 1