Пример #1
0
 def is_user(username, password):
     try:
         session.query(User).filter(User.username == username,
                                    User.password == password).one()
     except Exception:
         return False
     else:
         return True
 def show_all_projections_with_avaliable_seats(movie_id):
     subquery = session.query(
         Reservation.projection_id,
         func.count(Reservation.projection_id).label('seats')).group_by(
             Reservation.projection_id).subquery()
     return tabulate(session.query(
         Projection.id, Projection.date, Projection.time, Projection.type,
         (100 - func.coalesce(subquery.c.seats, 0))).outerjoin(
             subquery, Projection.id == subquery.c.projection_id).filter(
                 Projection.movie_id == movie_id).all(),
                     headers=['id', 'date', 'time', 'type', 'spots'],
                     tablefmt="plain")
 def show_all_projections_by_date(movie_id, date):
     return tabulate(session.query(
         Projection.id, Projection.time, Projection.type).filter(
             Projection.movie_id == movie_id,
             Projection.date == date).order_by(Projection.time).all(),
                     headers=['id', 'time', 'type'],
                     tablefmt="plain")
Пример #4
0
 def check_projection_for_avaliable_seats(projection_id, tickets):
     avaliable = 100 - session.query(Reservation).filter(
         Reservation.projection_id == projection_id).count()
     if tickets > avaliable:
         return False
     else:
         return True
Пример #5
0
 def show_all_reservations(projection_id):
     return tabulate(session.query(
         Reservation.projection_id, Reservation.row,
         Reservation.col).filter(
             Reservation.projection_id == projection_id).all(),
                     headers=['projection', 'row', 'column'],
                     tablefmt="plain")
 def get_movie(id):
     movie = session.query(Movie).filter(Movie.id == id).one()
     return movie.id
 def show_all_movies():
     return tabulate(session.query(Movie.id, Movie.name,
                                   Movie.rating).all(),
                     headers=['id', 'title', 'rating'],
                     tablefmt="plain")
Пример #8
0
def check_seat(projection_id, row, column):
    reserved = session.query(Reservation.row, Reservation.col).filter(
        Reservation.projection_id == projection_id).all()
    if (row, column) in reserved:
        raise NotValidSeat("This seat is already taken!")
 def show_projection_info(projection_id):
     return session.query(Movie.name, Movie.rating, Projection.date,
                          Projection.time, Projection.type).filter(
                              Projection.movie_id == Movie.id,
                              Projection.id == projection_id).one()
Пример #10
0
 def show_projection_spots(projection_id):
     reserved = session.query(
         Reservation.row, Reservation.col).filter(
         Reservation.projection_id == projection_id).all()
     return tabulate(Board.create(reserved), tablefmt='plain')
Пример #11
0
 def delete(reservation_id):
     item = session.query(Reservation).filter(
         Reservation.id == reservation_id).one()
     session.delete(item)
Пример #12
0
 def log_out(user_id):
     user = session.query(User).filter(User.id == user_id).one()
     user.is_active = 0
     session.commit()
Пример #13
0
 def logged(username, password):
     user = session.query(User).filter(User.username == username,
                                       User.password == password).one()
     user.is_active = 1
     session.commit()
Пример #14
0
 def is_logged(username, password):
     user = session.query(User).filter(User.username == username,
                                       User.password == password).one()
     return True if user.is_active == 1 else False
Пример #15
0
 def get(username, password):
     user = session.query(User).filter(User.username == username,
                                       User.password == password).one()
     return user.id