def create(self) : self._id='org.couchdb.user:'******'yapooler') #TODO: check if it return the last version profile=Profile(owner=self._id) print profile.owner profileCreated = profile.create() if profileCreated : self.store(getDb()) return self else : return None else : print 'required parameters have not been supplied: login, email and password needed' return None else : print 'username already in used: ', self.name return None
def create(self): self._id = 'org.couchdb.user:'******'yapooler') #TODO: check if it return the last version profile = Profile(owner=self._id) print profile.owner profileCreated = profile.create() if profileCreated: self.store(getDb()) return self else: return None else: print 'required parameters have not been supplied: login, email and password needed' return None else: print 'username already in used: ', self.name return None
def findBySessionId(self) : view=dblayer.view("user/sessionId",self.sessionId) if len(view) == 0 : return None elif len(view) == 1: for u in view : return User.load(getDb(),u.id) else : print 'WARNING: critical error, more than one user with sthe same session Id ' raise IntegrityConstraintException
def update(self) : ''' update the user, only if he already exist ''' if self.id : self.store(getDb()) else : print 'invalid state, attemp to update a non existing user' raise IllegalAttempt
def findByActivationCode(self) : view=dblayer.view('user/activationCode',self.activationCode) if len(view) == 0 : return None elif len(view) == 1: for u in view : return User.load(getDb(),u.id) else : print 'WARNING: critical error, more than one user with same activation Code ' raise IntegrityConstraintException
def create(self) : #to ensure database integrity, it is mandatory to use this method the first time to creat a new user if self.findByLogin() == None : self.isActivated=False self.type=self.TYPE self.store(getDb()) #TODO: check if it return the last version return self else : print 'a user already exist for login: ', self.login return None
def switchToTestDatabase(replicate=True) : ''' this method change the database to a test database the default argument replicate mean that the database is replicate from the original so the design document are replicated ''' print '\n------------------Running the couchdbinterface test -------------------------\n' print 'switching to test database' #easy way to make sure we have a clean database dblayer.db=loadDatabase(server,TEST_DB_NAME) if replicate : server.replicate(dblayer.DB_NAME,TEST_DB_NAME) print 'DATABASE TEST ENVIRONMENT: ',server,',',getDb()
def findByLogin(self) : ''' return the actual version of the user. ''' view=dblayer.view("user/login",self.login) if len(view) == 0 : return None elif len(view) == 1: #TODO optimize for u in view : return User.load(getDb(),u.id) else : print 'WARNING: critical error, more than one user for same login' raise IntegrityConstraintException
def findById(self) : view=dblayer.view("keyword/id",self._id) if len(view) == 0 : return None elif len(view) == 1: for u in view : return Article.load(getDb(),u.id)
def update(self) : self.store(getDb())
def create(self) : if self.findById() == None : self.popularity=0 self.type=self.TYPE self.store(getDb())