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")
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
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")
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()
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')
def delete(reservation_id): item = session.query(Reservation).filter( Reservation.id == reservation_id).one() session.delete(item)
def log_out(user_id): user = session.query(User).filter(User.id == user_id).one() user.is_active = 0 session.commit()
def logged(username, password): user = session.query(User).filter(User.username == username, User.password == password).one() user.is_active = 1 session.commit()
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
def get(username, password): user = session.query(User).filter(User.username == username, User.password == password).one() return user.id