Beispiel #1
0
 def Post(name):
     exercise = ExerciseType.NullObject()
     if ExerciseType.Count(name) == 0:
         exercise = ExerciseType(name=name.lower())
         Session.add(exercise)
         Session.commit()
     else:
         exercise = ExerciseType.GetByName(name)
     return exercise
Beispiel #2
0
 def DeleteByName(name):
     item = ExerciseType.GetByName(name)
     Session.delete(item)
     result = Session.commit()
     print result
     return json.dumps({
         "data_type": "request_confirmation",
         "status": "FAILURE"
     })
Beispiel #3
0
def home():
    ses = Session()
    ses.add_all([
        Car(Id=1, Name='Audi', Price=52642),
        Car(Id=2, Name='Mercedes', Price=57127),
        Car(Id=3, Name='Skoda', Price=9000),
        Car(Id=4, Name='Volvo', Price=29000),
        Car(Id=5, Name='Bentley', Price=350000),
        Car(Id=6, Name='Citroen', Price=21000),
        Car(Id=7, Name='Hummer', Price=41400),
        Car(Id=8, Name='Volkswagen', Price=21600)
    ])
    ses.commit()

    rs = ses.query(Car).all()
    for Car in rs:
        print(Car.Name, Car.Price)
    return rs
Beispiel #4
0
from Database import engine, Base, Session
from models import User

Base.metadata.create_all(engine)

session = Session()

session.commit()
session.close()
Beispiel #5
0
class SessionManager(object):
    user = None

    def __init__(self):
        self.dbsession = Session()

    def __del__(self):
        self.dbsession.close()

    def IsLoggedIn(self):
        if self.user == None:
            return False

        return True

    def Login(self, userid, password):
        user = self.dbsession.query(User).filter(User.id == userid).first()

        print userid
        print user

        if user != None:
            if user.password == password:
                if 'LOGIN' in user.privilages:
                    self.user = user
                    self.loginSession()
                    return True
        return False

    def Logout(self):
        self.logoutSession()
        self.user = None

    def loginSession(self):
        now = datetime.now()

        self.userSession = UserSession(user_id=self.user.id,
                                       time=now,
                                       host='127.0.0.1',
                                       port=0)

        self.dbsession.add(self.userSession)
        self.dbsession.commit()

        sessionlog = UserSessionLog(user_id=self.user.id,
                                    time=now,
                                    host=self.userSession.host,
                                    port=self.userSession.port,
                                    action='LOGIN')

        self.dbsession.add(sessionlog)
        self.dbsession.commit()

    def logoutSession(self):
        if self.userSession != None:
            now = datetime.now()

            sessionlog = UserSessionLog(user_id=self.user.id,
                                        time=now,
                                        host=self.userSession.host,
                                        port=self.userSession.port,
                                        action='LOGOUT')

            self.dbsession.add(sessionlog)

            self.dbsession.delete(self.userSession)

            self.dbsession.commit()

            self.userSession = None