Exemple #1
0
 def set_last_online(self, when):
     session = SessionFactory()
     try:
         user = session.query(User).filter_by(id=self.id).one()
         user.last_online = when
         session.add(user)
         session.commit()
     finally:
         session.close()
Exemple #2
0
 def get_user(cls, username):
     session = SessionFactory()
     try:
         user = session.query(User).filter_by(username=username).one()
         return user
     except NoResultFound:
         user = User(username)
         session.add(user)
         session.commit()
         print "Created new user entry in the database for user '{}'.".format(username)
     finally:
         session.close()
         
     # If the entry for the user was just created then retreive the committed version
     session = SessionFactory()
     try:
         user = session.query(User).filter_by(username=username).one()
         return user
     except NoResultFound:
         return None
     finally:
         session.close()