Ejemplo n.º 1
0
    def _add_book(self):
        if self.current_page == 'SEARCH':
            if self.current_entry:
                self.added_book = self.current_entry.to_book(
                    self.current_entry.isbns[0])
                if not Book.exists(self.added_book.isbn, self.db):
                    self.db.add(self.added_book)
                    self.is_new = True
                self.dialog.close()
            else:
                self.show_message(
                    'You need to select a book to add to the library.')
        elif self.current_page == 'MANUAL':
            isbn = self.builder.get_object('entry_isbn').get_text().strip()
            title = self.builder.get_object('entry_title').get_text().strip()
            author = self.builder.get_object('entry_author').get_text().strip()
            own = self.builder.get_object('chk_own').get_active()
            want = self.builder.get_object('chk_want').get_active()
            read = self.builder.get_object('chk_read').get_active()

            if not title:
                self.lbl_manual_message.set_text('Please enter a title.')
                return
            elif not author:
                self.lbl_manual_message.set_text('Please enter an author.')
                return

            self.added_book = Book(isbn=isbn,
                                   title=title,
                                   author=author,
                                   own=own,
                                   want=want,
                                   read=read)
            if ((isbn != '' and not Book.exists(isbn, self.db))
                    or not Book.exists_author_title(author, title, self.db)):
                self.db.add(self.added_book)
                self.is_new = True
            self.dialog.close()