def __init__(self): self.mongo = MongoBackend() self.db = self.mongo.get_database() self.desc = DESCENDING self.asc = ASCENDING self.collection = None # Defined in the child models
class BaseModel(object): def __init__(self): self.mongo = MongoBackend() self.db = self.mongo.get_database() self.desc = DESCENDING self.asc = ASCENDING self.collection = None # Defined in the child models # CRUD Methods def insert(self, data): self.collection.insert(data) def update(self, data, id): try: object_id = self.mongo.get_object_id(id) except: object_id = False if object_id: self.collection.update({"_id": object_id}, {"$set": data}, upsert=True) def get_one(self): return self.collection.find_one() def get_all(self): return self.collection.find() def get_by_id(self,id): try: object_id = self.mongo.get_object_id(id) except: object_id = False if object_id: return self.collection.find_one({"_id": object_id}) def delete(self, id): try: object_id = self.mongo.get_object_id(id) except: object_id = False if object_id: self.collection.remove(object_id)
class BaseModel(object): def __init__(self): self.mongo = MongoBackend() self.db = self.mongo.get_database() self.desc = DESCENDING self.asc = ASCENDING self.collection = None # Defined in the child models # CRUD Methods def insert(self, data): self.collection.insert(data) def update(self, data, id): try: object_id = self.mongo.get_object_id(id) except: object_id = False if object_id: self.collection.update({"_id": object_id}, {"$set": data}, upsert=True) def get_one(self): return self.collection.find_one() def get_all(self): return self.collection.find() def get_by_id(self, id): try: object_id = self.mongo.get_object_id(id) except: object_id = False if object_id: return self.collection.find_one({"_id": object_id}) def delete(self, id): try: object_id = self.mongo.get_object_id(id) except: object_id = False if object_id: self.collection.remove(object_id)
'duration': self.duration, 'expires': self.expires, 'ip_address': self.ip_address, 'user_agent': self.user_agent, 'security_model': self.security_model, 'regeneration_interval': self.regeneration_interval, 'next_regeneration': self.next_regeneration } return base64.encodestring(pickle.dumps(dump)) @staticmethod def deserialize(datastring): return pickle.loads(base64.decodestring(datastring)) mongo_backend = MongoBackend() mongo = mongo_backend.get_collection('sessions') class MongoDBSession(BaseSession): """Class implementing the MongoDB based session storage. All sessions are stored in a collection "sessions" in the db you specify in the session_storage setting. The session document structure is following: 'session_id': session ID 'data': serialized session object 'expires': a timestamp of when the session expires, in sec since epoch 'user_agent': self-explanatory An index on session_id is created automatically, on application's init.
'data': self.data, 'duration': self.duration, 'expires': self.expires, 'ip_address': self.ip_address, 'user_agent': self.user_agent, 'security_model': self.security_model, 'regeneration_interval': self.regeneration_interval, 'next_regeneration': self.next_regeneration} return base64.encodestring(pickle.dumps(dump)) @staticmethod def deserialize(datastring): return pickle.loads(base64.decodestring(datastring)) mongo_backend = MongoBackend() mongo = mongo_backend.get_collection('sessions') class MongoDBSession(BaseSession): """Class implementing the MongoDB based session storage. All sessions are stored in a collection "sessions" in the db you specify in the session_storage setting. The session document structure is following: 'session_id': session ID 'data': serialized session object 'expires': a timestamp of when the session expires, in sec since epoch 'user_agent': self-explanatory An index on session_id is created automatically, on application's init. The end_request() is called after every operation (save, load, delete),