def searchBookById(self, book_id): ''' :param book_id: :return: ''' book = Book(book_id, 'None', 'None', 'None', None) self.__valid.checkBookExistence(book, self.__bookRepo.getAll()) book_repo = self.__bookRepo.getAll() for book in book_repo: if book_id == book.get_book_id(): return book
def import_data(): prefix_path = "Files/Books/" book_names = glob.glob(prefix_path + "*") for book_name in book_names: Book(book_name.split('/')[-1]) lesson_names = glob.glob(book_name + "/*") for lesson_name in lesson_names: lesson = Lesson( book_name.split('/')[-1], lesson_name.split('/')[-1]) reading_names = glob.glob(lesson_name + "/*") for reading_name in reading_names: Reading(lesson, reading_name.split('/')[-1]) with open(reading_name) as file: for line in file: word_array = line.split(';') assert len(word_array) == 3 add_word( word_array[1], WordOccur( book_name.split('/')[-1], lesson_name.split('/')[-1], reading_name.split('/')[-1], int(word_array[0])), [ word_name.strip() for word_name in word_array[2].split(',') ])
def addBook(self): authors = [] genres = [] for i in range(0, self.authorModel.rowCount()): item = self.authorModel.item(i) if item.checkState(): authors.append(Author(*item.text().split(" "))) for i in range(0, self.genreModel.rowCount()): item = self.genreModel.item(i) if item.checkState(): genres.append(Genre(item.text())) title = self.ui.bookTitleLineEdit.text() year = self.ui.yearSpinBox.value() mark = self.ui.markSpinBox.value() book = Book(title, year, mark, authors, genres) book.save() self.close()
def returnBook(self, book_id): book = Book(book_id, None, None, None, None) self.__valid.checkBookExistence(book, self.__bookService.getAllBooks()) self.__bookService.setBookAvailable(book_id) rental = self.searchRentalByBookId(book_id) # setting the returned date current_date = datetime.now() returned_date = date(current_date.year, current_date.month, current_date.day) rental.set_returned_date(returned_date) #the undo undo = FunctionCall(self.undoReturnBook, book_id) redo = FunctionCall(self.returnBook, book_id) operation = Operation(undo, redo) self.__undoService.add_operation(operation)
def createRental(self, rental_id, book_id, client_id): book_repo = self.__bookService.getAllBooks() client_repo = self.__clientService.getAllClients() # we create a new client in order to see if client_id valid or not client = Client(client_id, 'None') self.__valid.checkClientExistence(client, client_repo) # we create a new book in order to see if the book_is valid or not book = Book(book_id, 'None', 'None', 'None', None) self.__valid.checkBookExistenceAndAvailability(book, book_repo) # need to check the book if it is available current_date = datetime.now() current_day = current_date.day # int current_month = current_date.month # int current_year = current_date.year # int rented_date = date(current_year, current_month, current_day) #rented_date = [] # rented_date will be a list #rented_date.append(current_day) #rented_date.append(current_month) #rented_date.append(current_year) # we need to create the due date due_date_p = current_date + timedelta(days=14) due_date_day = due_date_p.day # int due_date_month = due_date_p.month # int due_date_year = due_date_p.year # int due_date = date(due_date_year, due_date_month, due_date_day) #due_date = [] # due_date will be a list #due_date.append(due_date_day) #due_date.append(due_date_month #due_date.append(due_date_year) returned_date = 0 rental = Rental(rental_id, book_id, client_id, rented_date, due_date, returned_date) return rental
def createBook(self, book_id, book_title, book_description, book_author): book = Book(book_id, book_title, book_description, book_author, True) return book
def undoReturnBook(self, book_id): book = Book(book_id, None, None, None, None) self.__valid.checkBookExistence(book, self.__bookService.getAllBooks()) self.__bookService.setBookUnavailable(book_id) rental = self.searchRentalByBookId(book_id) rental.set_returned_date(0)
# coding: utf-8 # take all classes from Models -> create in time of initialization from DB_shell import DB from Models.Book import Book from Models.Plane import Plane db = DB('my_db') my_book = Book(book_id=1, title='Martin Iden', summary='Super interesting book', comment='my comment') db.add(my_book) # my_plane = Plane(plane_id = 1, name='Afrodita') db.add(my_book) db.commit()