Browse Source

Added the emfield_upgrade method (for the update of an existing field)

Roland Haroutiounian 8 years ago
parent
commit
d309cea519

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

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

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

@@ -122,9 +122,17 @@ class MongoDbMigrationHandler(object):
122 122
 
123 123
     ## @brief upgrades a field
124 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 137
         ## @brief Defines the default value when a new field is added to a collection's items
130 138
     # @param fieldtype str : name of the field's type

Loading…
Cancel
Save