def storeToFile(self): try: file = open(self.__fileName, 'w') rentalList = RentalRepository.getAllRentals(self) for rental in rentalList: stringToStore = str(rental.getRentalId()) + ";" + str(rental.getMovieId()) + ";" + \ str(rental.getClientId()) + ";" rentedDateString = str(rental.getRentedDate().year) + "/" + \ str(rental.getRentedDate().month) + "/" + \ str(rental.getRentedDate().day) dueDateString = str(rental.getDueDate().year) + "/" + \ str(rental.getDueDate().month) + "/" + \ str(rental.getDueDate().day) + "" if rental.isReturned(): returnedDateString = str(rental.getReturnDate().year) + "/" + \ str(rental.getReturnDate().month) + "/" + \ str(rental.getReturnDate().day) else: returnedDateString = "None" stringToStore = stringToStore + rentedDateString + ";" + dueDateString + ";" +\ returnedDateString + "\n" file.write(stringToStore) except IOError: raise FileRepositoryException("Rental File Error") finally: file.close()
def getAllRentals(self): return RentalRepository.getAllRentals(self)