def choose_projection(cls, movie_id): from view.menu import Menu menu = """ 1)Choose a projection 2)Cancel reservation """ while (True): MovieController.show_projections_of_movie(movie_id) kwargs = Menu.get_input(menu, option=None) option = kwargs['option'] if option == '1': try: kwargs = Menu.get_input('', projection_by_id=None) projection_id = kwargs['projection_by_id'] if cls.is_valid_id(projection_id, 'projection'): return projection_id else: print("Invalid id\n") except Exception: print("Invalid input!\n") elif option == '2': raise Exception("Canceling reservation...") else: print('Invalid option\n')
def add_projection(cls, movie_id, type, date, time): if MovieController.check_id(movie_id) is False: raise Exception( 'Movie with id = {} doesn\'t exist!'.format(movie_id)) session.add(Projection(movie_id, type, date, time)) session.commit()
def show_movie_projections(cls, movie_id): try: movie_name = MovieController.get_movie(movie_id).name projections = ProjectionController.get_all_projections_for_movie( movie_id) except MovieException: raise Exception('Invalid movie id!') rows = [[p.id, p.date, p.time, p.type] for p in projections] cls.show_message(f'Projections for movie {movie_name}:') cls.show_table(rows, ['ID', 'Date', 'Time', 'type'])
def choose_a_movie(cls): from view.menu import Menu menu = """ 1)Choose a movie 2)Cancel reservation """ while (True): MovieController.show_all_movies() kwargs = Menu.get_input(menu, option=None) option = kwargs['option'] if option == '1': movie_id = cls.obtain_movie_id() if movie_id: return movie_id else: print("Invalid movie id!") elif option == '2': raise Exception("Canceling reservation...") else: print("Invalid option")
class MovieInterface: validator = CinemaValidator() movie_controller = MovieController() reservation_controller = ReservationController() def choose_movie(self): while True: try: self.show_movies() movie_id = input('Choose movie id:\n>>> ') self.validator.validate_movie_id(cast_to_int(movie_id)) except MovieDoesntExist as e: print(e) except ValueError as e: print(e) else: return movie_id def choose_movie_projection(self, movie_id): while True: try: self.show_movie_projections(movie_id) projection_id = input('Choose projection id:\n>>> ') self.validator.validate_projection_id( cast_to_int(projection_id), movie_id) except ProjectionDoesntExist as e: print(e) except ValueError as e: print(e) else: return projection_id def show_movies(self): pretty_print_movies(self.movie_controller.list_movies()) def show_movie_projections(self, id_, date=None): pretty_print_movie_projections( self.movie_controller.show_movie_projections( cast_to_int(id_), date)) def show_room_matrix_for_projection(self, proj_id, seats=None): matrix = [['.' for _ in range(MAX_ROWS)] for _ in range(MAX_COLS)] taken_seats = self.reservation_controller.get_taken_seats_for_projection( proj_id) for seat in taken_seats: matrix[seat[0] - 1][seat[1] - 1] = 'x' if seats: for seat in seats: matrix[seat[0] - 1][seat[1] - 1] = '#' print_matrix_hall(matrix)
def show_start_menu(self): command = '' while command != 'exit': command = input(f'\n{self.start_menu}\n\nOption:\n>>>') if command == '1': MainController.show_movies() elif command == '2': movie_id = input('Movie_id >>>') if movie_id.isdigit() is False or MovieController.check_id( int(movie_id)) is False: print('Invalid movie ID!') else: MainController.show_movie_projections(int(movie_id)) elif command == '3': try: self.make_reservation_menu() except CancelException as e: print('The reservation was canceled!') elif command != 'exit': print('Invalid option!')
def make_reservation_menu(self): self.login_register_menu() if self.user is None: return print(f'Hello, {self.user.username}') MainController.show_movies() movie_id = self.get_number_input('Movie ID >>> ', MovieController.check_id) number_of_tickets = self.get_number_input('Number of tickets >>> ', lambda x: int(x) > 0) MainController.show_movie_projections(movie_id) projection_id = self.get_number_input( 'Choose a projection >>> ', lambda p_id: MovieController.check_id_for_projection( movie_id, int(p_id))) self.pick_seats_menu(projection_id, number_of_tickets) self.finalize_menu()
def get_all_projections_for_movie(cls, movie_id): if MovieController.check_id(movie_id) is False: return None return session.query(Projection).filter(Projection.movie_id == movie_id).\ order_by(Projection.date).all()
def show_movies(cls): movies = MovieController.get_all_movies() rows = [[movie.id, movie.name, movie.rating] for movie in movies] cls.show_table(rows, ['ID', 'Movie title', 'rating'])
def show_projections_of_movie(cls, movie_id): return MovieController.show_projections_of_movie(movie_id)
def show_all_movies(cls): return MovieController.show_all_movies()
def test_get_movie_with_incorrect_id(self): movie_id = 42 with self.assertRaises(MovieIdError): MovieController.get_by_id(movie_id)
def test_get_movie_with_correct_id(self): movie_id = 1 expected = (1, "The Hunger Games: Catching Fire", 7.5) actual = MovieController.get_by_id(movie_id) self.assertEqual(expected, actual)
def test_get_all_movies(self): expected = [(1, "The Hunger Games: Catching Fire", 7.5), (2, "Wreck-It Ralph", 7.8), (3, "Her", 8.3), (4, "Avengers: Infinity War", 8.8)] actual = MovieController.get_all() self.assertEqual(expected, actual)
def test_create_with_incorrect_rating(self): with self.assertRaises(MovieRatingOutOfRangeError): MovieController.create("Movie with wrong rating", -5)
def insert_new_movie(cls, *args): MovieController.insert_new_movie(cls, *args)
from controllers.movie_controller import MovieController from controllers.user_controller import UserController from controllers.reservation_controller import ReservationController m = MovieController() u = UserController() r = ReservationController() def pop(): # m.add_new_movie(movie_name='LODR', movie_rating=9) # m.add_new_movie(movie_name='bbee', movie_rating=3) # m.add_new_movie(movie_name='star', movie_rating=2) # m.add_new_movie(movie_name='wars', movie_rating=5) # m.add_new_movie(movie_name='13', movie_rating=5) # u.create_new_user(user_name='Ivan', password='******') # u.create_new_user(user_name='Ivan2', password='******') # u.create_new_user(user_name='Ivan3', password='******') # u.create_new_user(user_name='Ivan4', password='******') # u.create_new_user(user_name='Ivan5', password='******') # u.create_new_user(user_name='Ivan6', password='******') # u.create_new_user(user_name='Ivan7', password='******') r.make_new_reservation(1, 2, 9, 9) r.make_new_reservation(1, 2, 9, 8) r.make_new_reservation(1, 2, 9, 7) r.make_new_reservation(1, 2, 9, 10) # p.create_new_projection(movie_id=1, type_='3D', date='2018-02-12', time='12:30:00') # p.create_new_projection(movie_id=2, type_='2D', date='2018-05-02', time='12:30:00') # p.create_new_projection(movie_id=3, type_='4D', date='2018-06-22', time='12:30:00')