def save(self): """Save this object into the database with all its public attributes.""" # Can't save without a database or a table if self._database is None: raise ValueError, "No database has been selected." if self._collection is None: raise ValueError, "No collection has been selected." # Check private variables. We probably shouldn't store these. document = {} for key, value in self.__dict__.items(): key = key.replace("_"+self._type, "") if key.startswith("__"): continue document[key] = value # Let's store this object storage = Storage() storage.getDatabase(self._database) storage.getCollection(self._collection) storage.insertDocuments(document) self._id = document["_id"]