예제 #1
0
 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
예제 #2
0
    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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
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()
예제 #8
0
 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
예제 #9
0
 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)
예제 #10
0
 def update(self) :
   self.store(getDb())
예제 #11
0
 def create(self) :
   if self.findById() == None :
     self.popularity=0
     self.type=self.TYPE
     self.store(getDb())