Beispiel #1
0
 def __ui_update_movie(self, parameters):
     if len(parameters) == 1:
         try:
             id = int(parameters[0])
             print("What parameter from the movie you want to update?\n"
                   "Options: \n"
                   "1: Title.\n"
                   "2: Description.\n"
                   "3: Genre.\n")
             attribute = ''
             new_value = ''
             command = input("Enter command: ")
             if command == '1':
                 new_value = input("Enter title: ")
                 attribute = 'title'
             elif command == '2':
                 new_value = input("Enter description: ")
                 attribute = 'description'
             elif command == '3':
                 new_value = input('Enter genre: ')
                 attribute = 'genre'
             if command in ['1', '2', '3']:
                 UndoRedoManager.add_undo_operation(self.__movie_service, UndoHandler.UPDATE_ENTITY_HANDLER,
                                                    copy.deepcopy(self.__movie_service.get_element_by_id(id)), id)
                 self.__movie_service.update_movie_parameters(id, attribute, new_value)
             else:
                 print("Wrong command.")
         except ValueError:
             print('ID must be a positive integer.')
     else:
         print('You have to enter the movie ID after command.')
Beispiel #2
0
 def __ui_redo_last_operation(self, parameters):
     if len(parameters) != 0:
         print('Wrong command..')
     else:
         try:
             UndoRedoManager.redo()
         except EmptyError as e:
             print(e)
Beispiel #3
0
 def  __ui_add_client(self, parameters):
     if len(parameters) != 2:
         print("It requires 2 parameters.")
     else:
         try:
             id = int(parameters[0])
             name = parameters[1]
             self.__client_service.add_client(id, name)
             UndoRedoManager.add_undo_operation([self.__client_service], UndoHandler.ADD_ENTITY_HANDLER,
                                                self.__client_service.get_element_by_id(id))
         except ValueError:
             print('The id has to be an integer.')
Beispiel #4
0
 def __ui_add_movie(self, parameters):
     if len(parameters) != 4:
         print("It requires 4 parameters.")
     else:
         try:
             id = int(parameters[0])
             title = parameters[1]
             description = parameters[2]
             genre = parameters[3]
             self.__movie_service.add_movie(id, title, description, genre)
             UndoRedoManager.add_undo_operation([self.__movie_service], UndoHandler.ADD_ENTITY_HANDLER, self.__movie_service.get_element_by_id(id))
         except ValueError:
             print('The id has to be an integer.')
Beispiel #5
0
 def __ui_update_client(self, parameters):
     if len(parameters) == 2:
         try:
             id = int(parameters[0])
             attribute = 'name'
             new_name = parameters[1]
             UndoRedoManager.add_undo_operation(self.__client_service, UndoHandler.UPDATE_ENTITY_HANDLER,
                                                self.__client_service.get_element_by_id(id), id)
             self.__client_service.update_client_parameters(id, attribute, new_name)
         except ValueError:
             print('ID must be a positive integer.')
     else:
         print('You have to enter the client ID after command.')
Beispiel #6
0
 def __ui_return_movie(self, parameters):
     if len(parameters) == 1:
         try:
             movie_id = int(parameters[0])
             new_returned_date = input("Enter the returned_date (format: day.month.year, year > 1000): ")
             rental_id = self.__rental_service.return_movie(movie_id, new_returned_date)
             UndoRedoManager.add_undo_operation(self.__rental_service, UndoHandler.RETURN_MOVIE_HANDLER, rental_id)
             print('The movie was returned with success.')
         except ValueError:
             print('Id must be an integer.')
         except ValidatorError as ve:
             print(ve)
     else:
         print('Wrong command.')
Beispiel #7
0
 def __ui_remove_client(self, parameters):
     if len(parameters) == 1:
         id = int(parameters[0])
         rentals_id = self.__rental_service.check_entity_id_in_rentals('client', id)
         if len(rentals_id):
             UndoRedoManager.add_undo_operation([self.__client_service, self.__rental_service], UndoHandler.DELETE_ENTITY_HANDLER,
                                       self.__client_service.get_list_of_clients()[id],
                                       self.__rental_service.get_list_of_certain_rentals(rentals_id))
             self.__rental_service.remove_multiple_entities(rentals_id)
         else:
             UndoRedoManager.add_undo_operation([self.__client_service], UndoHandler.DELETE_ENTITY_HANDLER,
                                       self.__client_service.get_list_of_clients()[id])
         self.__client_service.remove_by_id(id)
     else:
         print('You have to enter one parameter.')
Beispiel #8
0
 def __ui_remove_movie(self, parameters):
     if len(parameters) == 1:
         try:
             id = int(parameters[0])
             rentals_id = self.__rental_service.check_entity_id_in_rentals('movie', id)
             if len(rentals_id) > 0:
                 UndoRedoManager.add_undo_operation([self.__movie_service, self.__rental_service], UndoHandler.DELETE_ENTITY_HANDLER,
                                       self.__movie_service.get_list_of_movies()[id],
                                       self.__rental_service.get_list_of_certain_rentals(rentals_id))
                 self.__rental_service.remove_multiple_entities(rentals_id)
             else:
                 UndoRedoManager.add_undo_operation([self.__movie_service], UndoHandler.DELETE_ENTITY_HANDLER,
                                           self.__movie_service.get_list_of_movies()[id])
             self.__movie_service.remove_by_id(id)
         except ValueError:
             print('Id must be an integer.')
     else:
         print('You have to enter one parameter.')
Beispiel #9
0
 def __ui_rent_a_movie(self, parameters):
     if len(parameters) == 0:
         try:
             rental_id = int(input("Enter id for rental: "))
             movie_id = int(input("Enter movie id: "))
             client_id = int(input("Enter client id: "))
             rented_date = input("Enter the rented_date (format: day.month.year, year > 1000): ")
             due_date = input("Enter the due_date (format: day.month.year, year > 1000): ")
             self.__rental_service.add_rental(rental_id, movie_id, client_id, rented_date, due_date, '', 'normal')
             UndoRedoManager.add_undo_operation([self.__rental_service], UndoHandler.ADD_ENTITY_HANDLER,
                                                self.__rental_service.get_element_by_id(rental_id))
             print('The movie was rented with success.')
         except ValueError:
             print('Id\'s must be integers.')
         except RentalError as re:
             print(re)
         except ValidatorError as ve:
             print(ve)
         except IndexError as ie:
             print('The format of the date was not ok.')