mirror of
				https://github.com/yweber/lodel2.git
				synced 2025-10-31 11:39:02 +01:00 
			
		
		
		
	Utilisation is_exist
This commit is contained in:
		
					parent
					
						
							
								d89203665b
							
						
					
				
			
			
				commit
				
					
						4fb0c89ddb
					
				
			
		
					 5 changed files with 19 additions and 20 deletions
				
			
		|  | @ -329,12 +329,15 @@ class Reference(DataHandler): | |||
|         if target_class not in self.__allowed_classes: | ||||
|             logger.warning('Class of the back_reference given is not an allowed class') | ||||
|             return False | ||||
|         target_uidfield = target_class.uid_fieldname()[0] #multi uid broken here | ||||
|         value = datas[fname] | ||||
|         obj = target_class.get([(target_uidfield, '=', value)]) | ||||
|         if len(obj) == 0: | ||||
|         if not target_class.is_exist(value): | ||||
|             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 | ||||
|  | @ -437,7 +440,7 @@ class MultipleRef(Reference): | |||
|             if len(left) == 0: | ||||
|                 return res | ||||
|         raise LodelDataHandlerConsistencyException("Unable to find \ | ||||
| some referenced objects. Followinf uid were not found : %s" % ','.join(left)) | ||||
| some referenced objects. Following uids were not found : %s" % ','.join(left)) | ||||
| 
 | ||||
| ## @brief Class designed to handle datas access will fieldtypes are constructing datas | ||||
| #@ingroup lodel2_datahandlers | ||||
|  | @ -446,7 +449,7 @@ some referenced objects. Followinf uid were not found : %s" % ','.join(left)) | |||
| # | ||||
| # In theory it's able to detect circular dependencies | ||||
| # @todo test circular deps detection | ||||
| # @todo test circulat deps false positiv | ||||
| # @todo test circular deps false positive | ||||
| class DatasConstructor(object): | ||||
| 
 | ||||
|     ## @brief Init a DatasConstructor | ||||
|  |  | |||
|  | @ -651,6 +651,12 @@ object ! For class %s with uid value = %s" % (cls, uid)) | |||
|             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) | ||||
| 
 | ||||
|  |  | |||
|  | @ -91,10 +91,7 @@ def admin_update(request): | |||
|     else: | ||||
|         # Check if the object actually exists | ||||
|         # We get it from the database | ||||
|         query_filters = list() | ||||
|         query_filters.append((uid_field,'=',lodel_id)) | ||||
|         obj = target_leo.get(query_filters) | ||||
|         if len(obj) == 0: | ||||
|         if not target_leo.is_exist(lodel_id): | ||||
|             raise HttpException(404) | ||||
|     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id) | ||||
| 
 | ||||
|  |  | |||
|  | @ -82,10 +82,7 @@ def show_object(request): | |||
|     if not test_valid: | ||||
|         raise HttpException(400) | ||||
|     else: | ||||
|         query_filters = list() | ||||
|         query_filters.append((uid_field,'=',lodel_id)) | ||||
|         obj = target_leo.get(query_filters) | ||||
|         if len(obj) == 0: | ||||
|         if not target_leo.is_exist(lodel_id): | ||||
|             raise HttpException(404) | ||||
|     return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname) | ||||
| 
 | ||||
|  | @ -121,10 +118,7 @@ def show_object_detailled(request): | |||
|     if not test_valid: | ||||
|         raise HttpException(400) | ||||
|     else: | ||||
|         query_filters = list() | ||||
|         query_filters.append((uid_field,'=',lodel_id)) | ||||
|         obj = target_leo.get(query_filters) | ||||
|         if len(obj) == 0: | ||||
|         if not target_leo.is_exist(lodel_id): | ||||
|             raise HttpException(404) | ||||
| 
 | ||||
|     return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname) | ||||
|  |  | |||
|  | @ -21,7 +21,6 @@ | |||
| 
 | ||||
| import sys, os, os.path | ||||
| import unittest | ||||
| import nocontext_tests | ||||
| 
 | ||||
| loader = unittest.TestLoader() | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 prieto
				prieto