def container_from_path(path): """ Return container object from path, None if nothing found. """ coll = Container.collection() dic = coll.find_one({"materialized_path": path}) return Container.unserialize(dic) if dic is not None else None
def get_container(container_id): """ Given container id, return container object. None if nothing found. """ coll = Container.collection() dic = coll.find_one({"_id": coerce_bson_id(container_id)}) return Container.unserialize(dic) if dic is not None else None
def child_containers(container_obj): """ Get all child containers of a given container """ child_container_dics = Container.collection().find({ "parent_id": container_obj.obj_id() if container_obj is not None else None, }) all_child_containers = [Container.unserialize(x) for x in child_container_dics] return all_child_containers
def remove_container(container_id): coll = Container.collection() coll.remove({"_id": coerce_bson_id(container_id)})
def save_container(container_obj): col = Container.collection() id = col.save(container_obj.serialize()) return id