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

Without is_exist

This commit is contained in:
prieto 2017-03-16 16:13:00 +01:00
commit b547f75c9f
5 changed files with 52 additions and 70 deletions

View file

@ -391,14 +391,11 @@ class Reference(DataHandler):
logger.warning('Class of the back_reference given is not an allowed class')
return False
value = datas[fname]
if not target_class.is_exist(value):
target_uidfield = target_class.uid_fieldname()[0] # multi uid broken here
obj = target_class.get([(target_uidfield, '=', value)])
if len(obj) == 0:
logger.warning('Object referenced does not exist')
return False
# target_uidfield = target_class.uid_fieldname()[0] #multi uid broken here
# obj = target_class.get([(target_uidfield, '=', value)])
# if len(obj) == 0:
# logger.warning('Object referenced does not exist')
# return False
return True
# @brief Utility method designed to fetch referenced objects

View file

@ -654,12 +654,3 @@ object ! For class %s with uid value = %s" % (cls, uid))
elif len(res) == 0:
return None
return res[0]
# @brief Checks if an object exists
@classmethod
def is_exist(cls, uid):
if cls.uid_fieldname() is None:
raise LodelFatalError(
"No uid defined for class %s" % cls.__name__)
from .query import is_exist
return is_exist(cls, uid)

View file

@ -13,18 +13,6 @@ 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):
@ -742,5 +730,3 @@ offset={offset}"
res %= (n, subq)
res += ">"
return res

View file

@ -91,7 +91,10 @@ def admin_update(request):
else:
# Check if the object actually exists
# We get it from the database
if not target_leo.is_exist(lodel_id):
query_filters = list()
query_filters.append((uid_field,'=',lodel_id))
obj = target_leo.get(query_filters)
if len(obj) == 0:
raise HttpException(404)
return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
@ -328,4 +331,3 @@ def process_form(request):
del(res)
raise HttpErrors(errors, title="Form validation error")
return res

View file

@ -82,7 +82,10 @@ def show_object(request):
if not test_valid:
raise HttpException(400)
else:
if not target_leo.is_exist(lodel_id):
query_filters = list()
query_filters.append((uid_field,'=',lodel_id))
obj = target_leo.get(query_filters)
if len(obj) == 0:
raise HttpException(404)
return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
@ -118,7 +121,10 @@ def show_object_detailled(request):
if not test_valid:
raise HttpException(400)
else:
if not target_leo.is_exist(lodel_id):
query_filters = list()
query_filters.append((uid_field,'=',lodel_id))
obj = target_leo.get(query_filters)
if len(obj) == 0:
raise HttpException(404)
return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)