mirror of
https://github.com/yweber/lodel2.git
synced 2025-12-03 17:26:54 +01:00
Added the emfield_upgrade method (for the update of an existing field)
This commit is contained in:
parent
11c6b2b53e
commit
d309cea519
2 changed files with 16 additions and 8 deletions
|
|
@ -33,7 +33,7 @@ class MongoDbDatasource(object):
|
|||
# @return list
|
||||
# @todo Implement the relations
|
||||
def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0, instanciate=True):
|
||||
collection_name = object_collection_name(target.__class__)
|
||||
collection_name = object_collection_name(target)
|
||||
collection = self.database[collection_name]
|
||||
query_filters = parse_query_filters(filters)
|
||||
query_result_ordering = parse_query_order(order) if order is not None else None
|
||||
|
|
@ -82,7 +82,7 @@ class MongoDbDatasource(object):
|
|||
def delete(self, target, uid):
|
||||
if isinstance(uid, dict):
|
||||
uid = [uid]
|
||||
collection_name = object_collection_name(target.__class__)
|
||||
collection_name = object_collection_name(target)
|
||||
collection = self.database[collection_name]
|
||||
result = collection.delete_many(uid)
|
||||
return result.deleted_count
|
||||
|
|
@ -96,7 +96,7 @@ class MongoDbDatasource(object):
|
|||
def update(self, target, uids, **datas):
|
||||
if not isinstance(uids, list):
|
||||
uids = [uids]
|
||||
collection_name = object_collection_name(target.__class__)
|
||||
collection_name = object_collection_name(target)
|
||||
collection = self.database[collection_name]
|
||||
results = collection.update_many({'uid': {'$in': uids}}, datas)
|
||||
return results.modified_count()
|
||||
|
|
@ -107,7 +107,7 @@ class MongoDbDatasource(object):
|
|||
# @return bool
|
||||
# @TODO Implement the error management
|
||||
def insert(self, target, **datas):
|
||||
collection_name = object_collection_name(target.__class__)
|
||||
collection_name = object_collection_name(target)
|
||||
collection = self.database[collection_name]
|
||||
result = collection.insert_one(datas)
|
||||
return len(result.inserted_id)
|
||||
|
|
@ -118,7 +118,7 @@ class MongoDbDatasource(object):
|
|||
# @return list : list of the inserted records' ids
|
||||
# @TODO Implement the error management
|
||||
def insert_multi(self, target, datas_list):
|
||||
collection_name = object_collection_name(target.__class__)
|
||||
collection_name = object_collection_name(target)
|
||||
collection = self.database[collection_name]
|
||||
result = collection.insert_many(datas_list)
|
||||
return len(result.inserted_ids)
|
||||
|
|
|
|||
|
|
@ -122,9 +122,17 @@ class MongoDbMigrationHandler(object):
|
|||
|
||||
## @brief upgrades a field
|
||||
# @todo to be implemented
|
||||
def _emfield_upgrade(self):
|
||||
# TODO check to see if the field's values in the collection corresponds to the new field type
|
||||
pass
|
||||
def _emfield_upgrade(self, model, uid, initial_state, new_state):
|
||||
collection_name = self._class_collection_name_from_field(model, initial_state)
|
||||
field_name = model.field(uid).name
|
||||
self._check_field_in_collection(collection_name, field_name, , initial_state, new_state)
|
||||
|
||||
def _check_field_in_collection(self,collection_name, field_name, initial_sate, new_state):
|
||||
collection = self.database[collection_name]
|
||||
cursor = collection.find({field_name: {'$exists': True}}, {field_name: 1})
|
||||
for document in cursor:
|
||||
# TODO vérifier que le champ contient une donnée compatible (document[field_name])
|
||||
pass
|
||||
|
||||
## @brief Defines the default value when a new field is added to a collection's items
|
||||
# @param fieldtype str : name of the field's type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue