mirror of
				https://github.com/yweber/lodel2.git
				synced 2025-10-31 11:39:02 +01:00 
			
		
		
		
	MongoDB datasource debugging + field_list handling changes in leobject -> query -> datasource chain
This commit is contained in:
		
					parent
					
						
							
								dddeae9c9e
							
						
					
				
			
			
				commit
				
					
						703b4adf7e
					
				
			
		
					 5 changed files with 32 additions and 13 deletions
				
			
		|  | @ -658,9 +658,7 @@ construction and consitency when datas are not complete\n") | |||
|     #@return a list of items (lists of (fieldname, fieldvalue)) | ||||
|     @classmethod | ||||
|     def get(cls, query_filters, field_list=None, order=None, group=None, limit=None, offset=0): | ||||
|         if field_list is None: | ||||
|             field_list = cls.fieldnames(True) | ||||
|         else: | ||||
|         if field_list is not None: | ||||
|             for uid in [ uidname | ||||
|                 for uidname in cls.uid_fieldname() | ||||
|                 if uidname not in field_list ]: | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ from lodel.settings.validator import SettingValidator | |||
| 
 | ||||
| CONFSPEC = { | ||||
|     'lodel2.datasource.mongodb_datasource.*':{ | ||||
|         'read_only': (True, SettingValidator('bool')), | ||||
|         'read_only': (False, SettingValidator('bool')), | ||||
|         'host': ('localhost', SettingValidator('host')), | ||||
|         'port': (None, SettingValidator('string')), | ||||
|         'db_name':('lodel', SettingValidator('string')), | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ from lodel import logger | |||
| from lodel.leapi.leobject import CLASS_ID_FIELDNAME | ||||
| 
 | ||||
| from . import utils | ||||
| from .utils import object_collection_name,\ | ||||
| from .utils import object_collection_name, collection_name, \ | ||||
|     MONGODB_SORT_OPERATORS_MAP, connection_string | ||||
| 
 | ||||
| class MongoDbDataSourceError(Exception): | ||||
|  | @ -133,13 +133,14 @@ class MongoDbDatasource(object): | |||
|         query_result_ordering = None | ||||
|         if order is not None: | ||||
|             query_result_ordering = utils.parse_query_order(order) | ||||
|         results_field_list = None if len(field_list) == 0 else field_list | ||||
|         limit = limit if limit is not None else 0 | ||||
| 
 | ||||
|          | ||||
|         if group is None: | ||||
|             cursor = collection.find( | ||||
|                 filter=query_filters, projection=results_field_list, | ||||
|                 skip=offset, limit=limit, sort=query_result_ordering) | ||||
|                 spec = query_filters, | ||||
|                 fields=field_list, | ||||
|                 skip=offset, | ||||
|                 limit=limit if limit != None else 0, | ||||
|                 sort=query_result_ordering) | ||||
|         else: | ||||
|             pipeline = list() | ||||
|             unwinding_list = list() | ||||
|  | @ -252,7 +253,8 @@ class MongoDbDatasource(object): | |||
|                         fname, op, val)) | ||||
|                     del(new_filters[i]) | ||||
|             new_filters.append( | ||||
|                 (CLASS_ID_FIELDNAME, '=', target_child.__name__)) | ||||
|                 (CLASS_ID_FIELDNAME, '=', | ||||
|                     collection_name(target_child.__name__))) | ||||
|             result += act( | ||||
|                 target = target_child, | ||||
|                 filters = new_filters, | ||||
|  | @ -436,17 +438,33 @@ class MongoDbDatasource(object): | |||
|     @classmethod | ||||
|     def __filters2mongo(cls, filters): | ||||
|         res = dict() | ||||
|         eq_fieldname = [] #Stores field with equal comparison OP | ||||
|         for fieldname, op, value in filters: | ||||
|             oop = op | ||||
|             ovalue = value | ||||
|             op, value = cls.__op_value_conv(op, value) | ||||
|             if op == '=': | ||||
|                 eq_fieldname.append(fieldname) | ||||
|                 if fieldname in res: | ||||
|                     logger.warning("Dropping previous condition. Overwritten \ | ||||
| by an equality filter") | ||||
|                 res[fieldname] = str(value) | ||||
|                 continue | ||||
|             if fieldname in eq_fieldname: | ||||
|                 logger.warning("Dropping condition : '%s %s %s'" % ( | ||||
|                     fieldname, op, value)) | ||||
|                 continue | ||||
| 
 | ||||
|             if fieldname not in res: | ||||
|                 res[fieldname] = dict() | ||||
|             if op in res[fieldname]: | ||||
|                 logger.warning("Dropping condition : '%s %s %s'" % ( | ||||
|                     fieldname, op, value)) | ||||
|             else: | ||||
|                 res[fieldname][op] = value | ||||
|                 if op not in cls.lodel2mongo_op_map: | ||||
|                     raise ValueError("Invalid operator : '%s'" % op) | ||||
|                 new_op = cls.lodel2mongo_op_map[op] | ||||
|                 res[fieldname][new_op] = value | ||||
|         return res | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -69,6 +69,9 @@ def connect(host, port, db_name, username, password): | |||
| def object_collection_name(class_object): | ||||
|     return class_object.__name__ | ||||
| 
 | ||||
| def collection_name(class_name): | ||||
|     return class_name | ||||
| 
 | ||||
| ## @brief Determine a collection field name given a lodel2 fieldname | ||||
| # @note For the moment this method only return the argument but EVERYWHERE | ||||
| # in the datasource we should use this method to gather proper fieldnames | ||||
|  |  | |||
|  | @ -259,7 +259,7 @@ class LeObjectQueryMockTestCase(unittest.TestCase): | |||
|             mock_init.assert_called_once_with( | ||||
|                 dyncode.Person, | ||||
|                 query_filters = ['lodel_id = 1'], | ||||
|                 field_list = dyncode.Person.fieldnames(True), | ||||
|                 field_list = None, | ||||
|                 order = None, group = None, limit = None, offset = 0) | ||||
| 
 | ||||
|         with patch.object( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yann
				Yann