Browse Source

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

prieto 9 years ago
parent
commit
05139b78b5

+ 3
- 1
lodel/leapi/query.py View File

64
         LodelHook.call_hook(    self._hook_prefix+'_pre',
64
         LodelHook.call_hook(    self._hook_prefix+'_pre',
65
                                 self._target_class,
65
                                 self._target_class,
66
                                 datas)
66
                                 datas)
67
-        ret = self.__query(self._datasource, **datas)
67
+        ret = self.__query(self._target_class._datasource, **datas)
68
         ret = LodelHook.call_hook(  self._hook_prefix+'_post',
68
         ret = LodelHook.call_hook(  self._hook_prefix+'_post',
69
                                     self._target_class,
69
                                     self._target_class,
70
                                     ret)
70
                                     ret)
461
         if nb_inserted < 0:
461
         if nb_inserted < 0:
462
             raise LeQueryError("Insertion error")
462
             raise LeQueryError("Insertion error")
463
         return nb_inserted
463
         return nb_inserted
464
+    """
464
     ## @brief Implements an insert query operation, with multiple insertions
465
     ## @brief Implements an insert query operation, with multiple insertions
465
     # @param datas : list of **datas to be inserted
466
     # @param datas : list of **datas to be inserted
466
     def __query(self, datas):
467
     def __query(self, datas):
469
         if nb_inserted < 0:
470
         if nb_inserted < 0:
470
             raise LeQueryError("Multiple insertions error")
471
             raise LeQueryError("Multiple insertions error")
471
         return nb_inserted
472
         return nb_inserted
473
+    """
472
 
474
 
473
     ## @brief Execute the insert query
475
     ## @brief Execute the insert query
474
     def execute(self, **datas):
476
     def execute(self, **datas):

+ 5
- 5
plugins/mongodb_datasource/main.py View File

33
     # @return list
33
     # @return list
34
     # @todo Implement the relations
34
     # @todo Implement the relations
35
     def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0, instanciate=True):
35
     def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0, instanciate=True):
36
-        collection_name = object_collection_name(target.__class__)
36
+        collection_name = object_collection_name(target)
37
         collection = self.database[collection_name]
37
         collection = self.database[collection_name]
38
         query_filters = parse_query_filters(filters)
38
         query_filters = parse_query_filters(filters)
39
         query_result_ordering = parse_query_order(order) if order is not None else None
39
         query_result_ordering = parse_query_order(order) if order is not None else None
82
     def delete(self, target, uid):
82
     def delete(self, target, uid):
83
         if isinstance(uid, dict):
83
         if isinstance(uid, dict):
84
             uid = [uid]
84
             uid = [uid]
85
-        collection_name = object_collection_name(target.__class__)
85
+        collection_name = object_collection_name(target)
86
         collection = self.database[collection_name]
86
         collection = self.database[collection_name]
87
         result = collection.delete_many(uid)
87
         result = collection.delete_many(uid)
88
         return result.deleted_count
88
         return result.deleted_count
96
     def update(self, target, uids, **datas):
96
     def update(self, target, uids, **datas):
97
         if not isinstance(uids, list):
97
         if not isinstance(uids, list):
98
             uids = [uids]
98
             uids = [uids]
99
-        collection_name = object_collection_name(target.__class__)
99
+        collection_name = object_collection_name(target)
100
         collection = self.database[collection_name]
100
         collection = self.database[collection_name]
101
         results = collection.update_many({'uid': {'$in': uids}}, datas)
101
         results = collection.update_many({'uid': {'$in': uids}}, datas)
102
         return results.modified_count()
102
         return results.modified_count()
107
     # @return bool
107
     # @return bool
108
     # @TODO Implement the error management
108
     # @TODO Implement the error management
109
     def insert(self, target, **datas):
109
     def insert(self, target, **datas):
110
-        collection_name = object_collection_name(target.__class__)
110
+        collection_name = object_collection_name(target)
111
         collection = self.database[collection_name]
111
         collection = self.database[collection_name]
112
         result = collection.insert_one(datas)
112
         result = collection.insert_one(datas)
113
         return len(result.inserted_id)
113
         return len(result.inserted_id)
118
     # @return list : list of the inserted records' ids
118
     # @return list : list of the inserted records' ids
119
     # @TODO Implement the error management
119
     # @TODO Implement the error management
120
     def insert_multi(self, target, datas_list):
120
     def insert_multi(self, target, datas_list):
121
-        collection_name = object_collection_name(target.__class__)
121
+        collection_name = object_collection_name(target)
122
         collection = self.database[collection_name]
122
         collection = self.database[collection_name]
123
         result = collection.insert_many(datas_list)
123
         result = collection.insert_many(datas_list)
124
         return len(result.inserted_ids)
124
         return len(result.inserted_ids)

+ 11
- 3
plugins/mongodb_datasource/migration_handler.py View File

122
 
122
 
123
     ## @brief upgrades a field
123
     ## @brief upgrades a field
124
     # @todo to be implemented
124
     # @todo to be implemented
125
-    def _emfield_upgrade(self):
126
-        # TODO check to see if the field's values in the collection corresponds to the new field type
127
-        pass
125
+    def _emfield_upgrade(self, model, uid, initial_state, new_state):
126
+        collection_name = self._class_collection_name_from_field(model, initial_state)
127
+        field_name = model.field(uid).name
128
+        self._check_field_in_collection(collection_name, field_name, , initial_state, new_state)
129
+
130
+    def _check_field_in_collection(self,collection_name, field_name, initial_sate, new_state):
131
+        collection = self.database[collection_name]
132
+        cursor = collection.find({field_name: {'$exists': True}}, {field_name: 1})
133
+        for document in cursor:
134
+            # TODO vérifier que le champ contient une donnée compatible (document[field_name])
135
+            pass
128
 
136
 
129
         ## @brief Defines the default value when a new field is added to a collection's items
137
         ## @brief Defines the default value when a new field is added to a collection's items
130
     # @param fieldtype str : name of the field's type
138
     # @param fieldtype str : name of the field's type

Loading…
Cancel
Save