Beispiel #1
0
 def checks_movie2(self, Id):
     '''
     Checks if a movie is in the list of availableMovies or not
     Input: Id - a number
     Output: -
     Exceptions: ControllerException from invalid Id or if the movie is not available
     '''
     self._validateID(Id)
     Id = int(Id)
     alls = self._repositoryMovie.get_all()
     available = self._repositoryMovie.get_available()
     if not Id in alls:
         raise ControllerException("There is no movie with the ID: " +
                                   str(Id) + "!\n")
     if Id in available:
         raise ControllerException("The movie with the ID: " + str(Id) +
                                   " is not rented!\n")
     return True
Beispiel #2
0
 def _validateID(self, Id):
     '''
     Validates ID
     Exceptions: Controller Exception when ID is not a number
     '''
     try:
         Id = int(Id)
     except ValueError:
         raise ControllerException("The ID should be a number!\n")
     return True
 def load_redo(self):
     '''
     load an operation from redolIst
     '''
     if self.__pos2 == len(self.__redoList) - 1:
         raise ControllerException("There is no further redo!\n")
     redo = self.__redoList[self.__pos2 + 1]
     self.__pos2 += 1
     self.__pos1 += 1
     return redo
 def load_undo(self):
     '''
     load an operation from undolIst
     '''
     if self.__pos1 == -1:
         raise ControllerException("There is no further undo!\n")
     undo = self.__undoList[self.__pos1]
     self.__pos1 -= 1
     self.__pos2 -= 1
     return undo
Beispiel #5
0
 def return_movie_Id(self, Id):
     '''
     Returns a movie with a certain Id
     '''
     self._validateID(Id)
     Id = int(Id)
     self.__validator.validateID(Id)
     movie = self._repository.return_movie_Id(Id)
     if not movie.get_availability():
         raise ControllerException("The movie is not available!\n")
     else:
         return movie
Beispiel #6
0
 def checks_client(self, Id):
     '''
     Checks if the client exists or not
     Input: Id - a number
     Output: -
     Exceptions: ControllerException from invalid Id or if the client can't be found
     '''
     self._validateID(Id)
     Id = int(Id)
     available = self._repositoryClient.get_all()
     if not Id in available:
         raise ControllerException("There is not client with the ID: " +
                                   str(Id) + "!\n")
     return True
Beispiel #7
0
 def edit_client(self, Id, Name):
     '''
     Edits the name of the client with a certain ID
     '''
     self._validateID(Id)
     Id = int(Id)
     if self._repository.find_by_ID(Id):
         client = self._repository.return_client_Id(Id)
         self._undoControl.store_undo(
             [Operation("edit_client", [Id, client.get_clientName()])])
         self._repository.update_client(Id, Name)
         self._undoControl.store_redo(
             [Operation("edit_client", [Id, Name])])
     else:
         raise ControllerException(
             "The client you want to edit can't be found!\n")
Beispiel #8
0
    def edit_movie(self, Id, Desc):
        '''
        Edits the description of the movie with a certain ID
        '''
        self._validateID(Id)
        Id = int(Id)
        if self._repository.find_by_ID(Id):
            movie = self._repository.return_movie_Id(Id)
            self._undoControl.store_undo(
                [Operation("edit_movie", [Id, movie.get_description()])])
            self._repository.update_movie(Id, Desc)
            self._undoControl.store_redo([Operation("edit_movie", [Id, Desc])])

        else:
            raise ControllerException(
                "The movie you want to edit can't be found!\n")
Beispiel #9
0
 def _generate_rentalID(self, Id):
     '''
         Generates a rental ID
         '''
     Rents = self._repositoryRental.get_all()
     for key in Rents:
         if Rents[key].get_rclientId(
         ) == Id and Rents[key].get_dueDate() < datetime.date.today():
             client = self._repositoryClient.return_client_Id(Id)
             movie = self._repositoryMovie.return_movie_Id(
                 Rents[key].get_rmovieId())
             if not movie.get_availability():
                 raise ControllerException(
                     "The client: '" + str(client.get_clientID()) + " - " +
                     str(client.get_clientName()) +
                     "' can't rent this movie!\nThe movie: '" +
                     str(movie.get_Id()) + " - " + str(movie.get_title()) +
                     "' passed the due date!\n")
     i = 1
     while i in Rents:
         i += 1
     return i