Exemplo n.º 1
0
 def removeBook(self, bookId):
     """the function removes the book with the ID given as parameter"""
     """it raises type error if the book wasn't found in the library"""
     for book in [rental.getBookID() for rental in self._repo.getRentals()]:
         if book.getID() == bookId:
             raise LibraryException("Book is rented...")
     self._repo.removeBook(bookId)
Exemplo n.º 2
0
 def findClientzById(self, id):
     """searches for a client by a certain id"""
     cls = self._repo.getClients()
     for c in cls:
         if c.getID() == id:
             return c.__str__()
     raise LibraryException("Client not found.")
 def undo(self):
     '''
     Function to handle the undo command, raises exception if there is nothing to be undone
     '''
     if self._now == 0:
         raise LibraryException("Already at earliest state!")
     else:
         self._now -= 1
    def redo(self):

        '''
        Function to handle the redo command, raises exception if there is nothing to be redone, when the now index is at the latest state
        '''
        if self._now == len(self._states) - 1:
            raise LibraryException("Already at newest state!")
        else:
            self._now += 1
Exemplo n.º 5
0
 def findBookById(self, id):
     """
     searches for a book with the given id
     """
     for b in self.getBooks():
         if b.getID() == id:
             return b
     raise LibraryException(
         "The book with entered title couldn't be found.")
Exemplo n.º 6
0
    def rentBook(self, rentalId, clientId, bookID, rentedDate, dueDate,
                 returnedDate):
        """
        book to return a book
        parameters:
        """
        clt = self.searchClient(clientId)
        bk = self.searchBook(bookID)
        if bk in [rental.getBook() for rental in self.getRentals()]:
            raise LibraryException("Book already rented to somebody!")

        for r in self.getRentals():
            if r.getRentalID() == rentalId:
                raise LibraryException(
                    "Already existing rental ID, choose another.")

        self._rentals.append(
            Rental(rentalId, bookID, clientId, rentedDate, dueDate, False))
 def saveLibraryHistory(self):
     """
     function to save all done operation in the libraryHisory.bin file\
     """
     try:
         with open("repository/libraryHistory.bin", "wb") as f:
             pickle.dump(self, f)
         return "Current state successfully saved!"
     except IOError:
         raise LibraryException("Current state couldn't be saved.")
Exemplo n.º 8
0
    def returnBook(self, clientId, bookID):
        client = self.searchClient(clientId)
        book = self.searchBook(bookID)

        for r in self.getRentals():
            if r.getBookID() == bookID and r.getClientId() == clientId:
                r.setReturnedDate(date.today())
                return
        raise LibraryException("Unrecognised rental.")
        """
Exemplo n.º 9
0
 def updateAuthor(self, bookId, newAuthor):
     """
     function to update the author of the book with id above given
     Parameters: the bookId and the new author
     Raises LibraryError if book wasn't found
     """
     for i in range(0, len(self._books)):
         if self._books[i].getID() == bookId:
             self._books[i].setAuthor(newAuthor)
             return
     raise LibraryException("Book not found.")
Exemplo n.º 10
0
 def updateTitle(self, bookId, newTitle):
     """
     function to update the title of the book with id above given
     Parameters: the bookId and the new title
     Raises LibraryError if book wasn't found
     """
     for i in range(0, len(self._books)):
         if self._books[i].getID() == bookId:
             self._books[i].setTitle(newTitle)
             return
     raise LibraryException("Book not found.")
Exemplo n.º 11
0
 def removeBook(self, id):
     """
     funtion to remove a book from the bookliss
     parameters : the book id
     raises LibraryException if the book was not found in the list
     """
     for i in range(0, len(self._books)):
         if self._books[i].getID() == id:
             del self._books[id]
             return
     raise LibraryException("Book not found.")
Exemplo n.º 12
0
 def updateClientName(self, clientId, newName):
     """
     function to update the name of the client with the id above given
     params: the id of the client and the new name
     raises LibraryException if the client doesn't exist in the list
     """
     for i in range(0, len(self._clients)):
         if self._clients[i].getID() == clientId:
             self._clients[i].setName(newName)
             return
     raise LibraryException("Client not found.")
Exemplo n.º 13
0
 def updateDescription(self, bookId, newDesc):
     """
     function to update the description of the book with id above given
     Parameters: the bookId and the new description
     Raises LibraryError if book wasn't found
     """
     for i in range(0, len(self._books)):
         if self._books[i].getID() == bookId:
             self._books[i].setDescription(newDesc)
             return
     raise LibraryException("Book not found.")
Exemplo n.º 14
0
 def searchBook(self, bookId):
     '''
     Function to search for a book in the list
     params:  bookId: the id of the book we want to search for
     returns the unique given book (since the id is unique)
     raises LibraryError Exception if the book was not found in the book list
     '''
     for i in range(len(self._books)):
         book = self._books[i]
         if book.getID() == bookId:
             return book
     raise LibraryException("Book not found!")
Exemplo n.º 15
0
 def removeClient(self, clientId):
     '''
     Function to remove a Client
     params clientId: the new client we want to remove
     raises exception if the client doesn't exist in the list
     '''
     for i in range(len(self._clients)):
         client = self._clients[i]
         if client.getId() == clientId:
             del self._clients[i]
             return
     raise LibraryException("Client not found!")
Exemplo n.º 16
0
 def searchClient(self, clientId):
     '''
     Function to search for a client by his unique id
     params: clientId: an integer representing the id of the client we want to search for
     returns the unique Client (since the id is unique)
     raises TypeError if there is no client with the given id
     '''
     for i in range(len(self._clients)):
         client = self._clients[i]
         if client.getID() == clientId:
             return client
     raise LibraryException("Client not found!")
Exemplo n.º 17
0
 def findRentalByBookID(self, bookID):
     """
     function to find an existing rental by the book id
     :param : the id of the book
     """
     for i in range(0, len(self._rentals)):
         rental = self._rentals[i]
         if rental.getBookID() == bookID:
             return rental
     raise LibraryException(
         "Book with ID: {0} doesn't exist or it is not rented.".format(
             bookID))
Exemplo n.º 18
0
    def removeRentalByBookId(self, bookId):
        """
        function to remove an existing rental by book id
        raises LibraryException if book wasn't found
        parameters: bookId
        """

        for i in range(0, len(self._rentals)):
            rental = self._rentals[i]
            if rental.getBookID() == bookId:
                del self._rentals[i]
                return
        raise LibraryException("Book not found.")
Exemplo n.º 19
0
 def removeClient(self, clientId):
     """
     function to remove the client with the given id
     params:  the client id
     
     """
     for client in [
             rental.getClients() for rental in self._repo.getRentals()
     ]:
         if client.getID() == clientId:
             raise LibraryException(
                 "Client has rented a book, return it and then remove the client..."
             )
     self._repo.removeClient(clientId)
Exemplo n.º 20
0
 def updateClientId(self, clientId, newClientId):
     """"
     function to update the client's with id above given id
     raises valueerror if the new id is already existing in the list
     params: the actual and the new id
     """
     try:
         self.searchClient(clientId)
         raise ValueError("Client id already existing.")
     except LibraryException:
         for client in self._clients:
             if client.getID() == clientId:
                 client.setID(newClientId)
                 return
         raise LibraryException("Client not found.")