Browse Source

Utilisation is_exist

prieto 8 years ago
parent
commit
4fb0c89ddb

+ 8
- 5
lodel/leapi/datahandlers/base_classes.py View File

329
         if target_class not in self.__allowed_classes:
329
         if target_class not in self.__allowed_classes:
330
             logger.warning('Class of the back_reference given is not an allowed class')
330
             logger.warning('Class of the back_reference given is not an allowed class')
331
             return False
331
             return False
332
-        target_uidfield = target_class.uid_fieldname()[0] #multi uid broken here
333
         value = datas[fname]
332
         value = datas[fname]
334
-        obj = target_class.get([(target_uidfield, '=', value)])
335
-        if len(obj) == 0:
333
+        if not target_class.is_exist(value):
336
             logger.warning('Object referenced does not exist')
334
             logger.warning('Object referenced does not exist')
337
             return False
335
             return False
336
+        #target_uidfield = target_class.uid_fieldname()[0] #multi uid broken here
337
+        #obj = target_class.get([(target_uidfield, '=', value)])
338
+        #if len(obj) == 0:
339
+        #    logger.warning('Object referenced does not exist')
340
+        #    return False
338
         return True
341
         return True
339
     
342
     
340
     ##@brief Utility method designed to fetch referenced objects
343
     ##@brief Utility method designed to fetch referenced objects
437
             if len(left) == 0:
440
             if len(left) == 0:
438
                 return res
441
                 return res
439
         raise LodelDataHandlerConsistencyException("Unable to find \
442
         raise LodelDataHandlerConsistencyException("Unable to find \
440
-some referenced objects. Followinf uid were not found : %s" % ','.join(left))
443
+some referenced objects. Following uids were not found : %s" % ','.join(left))
441
 
444
 
442
 ## @brief Class designed to handle datas access will fieldtypes are constructing datas
445
 ## @brief Class designed to handle datas access will fieldtypes are constructing datas
443
 #@ingroup lodel2_datahandlers
446
 #@ingroup lodel2_datahandlers
446
 #
449
 #
447
 # In theory it's able to detect circular dependencies
450
 # In theory it's able to detect circular dependencies
448
 # @todo test circular deps detection
451
 # @todo test circular deps detection
449
-# @todo test circulat deps false positiv
452
+# @todo test circular deps false positive
450
 class DatasConstructor(object):
453
 class DatasConstructor(object):
451
 
454
 
452
     ## @brief Init a DatasConstructor
455
     ## @brief Init a DatasConstructor

+ 8
- 2
lodel/leapi/leobject.py View File

651
             return None
651
             return None
652
         return res[0]
652
         return res[0]
653
 
653
 
654
-        
655
-        
654
+    ##@brief Checks if an object exists
655
+    @classmethod
656
+    def is_exist(cls, uid):
657
+        if cls.uid_fieldname() is None:
658
+            raise LodelFatalError(
659
+                "No uid defined for class %s" % cls.__name__)
660
+        from .query import is_exist
661
+        return is_exist(cls, uid)
656
 
662
 

+ 1
- 4
lodel/plugins/webui/interface/controllers/admin.py View File

91
     else:
91
     else:
92
         # Check if the object actually exists
92
         # Check if the object actually exists
93
         # We get it from the database
93
         # We get it from the database
94
-        query_filters = list()
95
-        query_filters.append((uid_field,'=',lodel_id))
96
-        obj = target_leo.get(query_filters)
97
-        if len(obj) == 0:
94
+        if not target_leo.is_exist(lodel_id):
98
             raise HttpException(404)
95
             raise HttpException(404)
99
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
96
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
100
 
97
 

+ 2
- 8
lodel/plugins/webui/interface/controllers/listing.py View File

82
     if not test_valid:
82
     if not test_valid:
83
         raise HttpException(400)
83
         raise HttpException(400)
84
     else:
84
     else:
85
-        query_filters = list()
86
-        query_filters.append((uid_field,'=',lodel_id))
87
-        obj = target_leo.get(query_filters)
88
-        if len(obj) == 0:
85
+        if not target_leo.is_exist(lodel_id):
89
             raise HttpException(404)
86
             raise HttpException(404)
90
     return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
87
     return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
91
 
88
 
121
     if not test_valid:
118
     if not test_valid:
122
         raise HttpException(400)
119
         raise HttpException(400)
123
     else:
120
     else:
124
-        query_filters = list()
125
-        query_filters.append((uid_field,'=',lodel_id))
126
-        obj = target_leo.get(query_filters)
127
-        if len(obj) == 0:
121
+        if not target_leo.is_exist(lodel_id):
128
             raise HttpException(404)
122
             raise HttpException(404)
129
 
123
 
130
     return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)
124
     return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)

+ 0
- 1
nocontext_tests.py View File

21
 
21
 
22
 import sys, os, os.path
22
 import sys, os, os.path
23
 import unittest
23
 import unittest
24
-import nocontext_tests
25
 
24
 
26
 loader = unittest.TestLoader()
25
 loader = unittest.TestLoader()
27
 
26
 

Loading…
Cancel
Save