コード例 #1
0
    def deleteBook(self):
        book_session.delete(self.book)
        book_session.commit()
        home_window = self.parent().findChild(QWidget, 'home_window')
        self.parent().setCurrentWidget(home_window)

        openDialog(QMessageBox.Information, 'Book deleted', 'Success')
コード例 #2
0
    def updateValues(self):
        try:

            counter_books = book_session.query(Book).count()

            genres = book_session.query(Genre).all()
            self.genre_series.clear()
            for genre in genres:
                genre_books = book_session.query(Book).filter_by(
                    genre_id=genre.id).count()
                self.genre_series.append(genre.name,
                                         genre_books / counter_books)

            for i in range(len(self.genre_series)):
                slice = QPieSlice()
                slice = self.genre_series.slices()[i]
                slice.setLabelVisible(True)

            authors = book_session.query(Author).all()
            self.author_series.clear()
            for author in authors:
                author_books = book_session.query(Book).filter_by(
                    author_id=author.id).count()
                self.author_series.append(author.name + " " + author.surname,
                                          author_books / counter_books)

            for i in range(len(self.author_series)):
                slice = QPieSlice()
                slice = self.author_series.slices()[i]
                slice.setLabelVisible(True)

            self.status_series.clear()
            all_status = book_session.query(BookStatus).all()
            counter_status = {}
            for status in all_status:
                book_status = book_session.query(Book).filter_by(
                    status_id=status.id).count()
                self.status_series.append(status.name,
                                          book_status / counter_books)

            for i in range(len(self.status_series)):
                slice = QPieSlice()
                slice = self.status_series.slices()[i]
                slice.setLabelVisible(True)
                if slice.label() == 'Not readed':
                    slice.setColor(QColor(255, 0, 0))
                elif slice.label() == 'In progress':
                    slice.setColor(QColor(0, 0, 255))
                elif slice.label() == 'Readed':
                    slice.setColor(QColor(0, 100, 0))

        except ZeroDivisionError:
            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)
            openDialog(QMessageBox.Critical, 'Insufficient data for chart',
                       'Error')
コード例 #3
0
    def deleteGenre(self):

        books = book_session.query(Book).filter_by(
            genre_id=self.genre.id).all()

        for book in books:
            book_session.delete(book)

        book_session.delete(self.genre)
        book_session.commit()
        home_window = self.parent().findChild(QWidget, 'home_window')
        self.parent().setCurrentWidget(home_window)

        openDialog(QMessageBox.Information, 'Genre deleted', 'Success')
コード例 #4
0
    def deleteGenre(self):

        movies = movie_session.query(Movie).filter_by(
            genre_id=self.genre.id).all()

        for movie in movies:
            movie_session.delete(movie)

        movie_session.delete(self.genre)
        movie_session.commit()
        home_window = self.parent().findChild(QWidget, 'home_window')
        self.parent().setCurrentWidget(home_window)

        openDialog(QMessageBox.Information, 'Genre deleted', 'Success')
コード例 #5
0
    def deleteFilmDirector(self):

        #CANCELLO TUTTI I FILM ASSOCIATI AL REGISTA
        movies = movie_session.query(Movie).filter_by(film_director_id=self.filmDirector.id).all()

        for movie in movies:
            movie_session.delete(movie)

        movie_session.delete(self.filmDirector)

        movie_session.commit()
        home_window = self.parent().findChild(QWidget, 'home_window')
        self.parent().setCurrentWidget(home_window)

        openDialog(QMessageBox.Information, 'Film director deleted', 'Success')
コード例 #6
0
    def updateValues(self):
        try:
            counter_movies = movie_session.query(Movie).count()

            genres = movie_session.query(Genre).all()
            self.genre_series.clear()
            for genre in genres:
                genre_movies = movie_session.query(Movie).filter_by(genre_id=genre.id).count()
                self.genre_series.append(genre.name, genre_movies/counter_movies)

            for i in range(len(self.genre_series)):
                slice = QPieSlice()
                slice = self.genre_series.slices()[i]
                slice.setLabelVisible(True)

            film_directors = movie_session.query(Film_director).all()
            self.filmDirector_series.clear()
            for film_director in film_directors:
                filmDirector_movie = movie_session.query(Movie).filter_by(film_director_id=film_director.id).count()
                self.filmDirector_series.append(film_director.name + " " + film_director.surname, filmDirector_movie/counter_movies)

            for i in range(len(self.filmDirector_series)):
                slice = QPieSlice()
                slice = self.filmDirector_series.slices()[i]
                slice.setLabelVisible(True)

            self.status_series.clear()
            all_status = movie_session.query(MovieStatus).all()
            counter_status = {}
            for status in all_status:
                movie_status = movie_session.query(Movie).filter_by(status_id = status.id).count()
                self.status_series.append(status.name, movie_status/counter_movies)

            for i in range(len(self.status_series)):
                slice = QPieSlice()
                slice = self.status_series.slices()[i]
                slice.setLabelVisible(True)
                if slice.label() == 'Not watched':
                    slice.setColor(QColor(255, 0, 0))
                elif slice.label() == 'Watched':
                    slice.setColor(QColor(0, 100, 0))
        
        except ZeroDivisionError:
            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)
            openDialog(QMessageBox.Critical, 'Insufficient data for chart', 'Error')

            
コード例 #7
0
    def deleteAuthor(self):

        #CANCELLO TUTTI I LIBRI ASSOCIATI ALL'AUTORE
        books = book_session.query(Book).filter_by(
            author_id=self.author.id).all()

        for book in books:
            book_session.delete(book)

        book_session.delete(self.author)

        book_session.commit()
        home_window = self.parent().findChild(QWidget, 'home_window')
        self.parent().setCurrentWidget(home_window)

        openDialog(QMessageBox.Information, 'Author deleted', 'Success')
コード例 #8
0
    def addAuthor(self):
        try:
            name = self.ui.authorName_lineEdit.text()
            surname = self.ui.authorSurname_lineEdit.text()

            if len(name) == 0: raise NoInputException('Enter author name')
            if len(surname) == 0: raise NoInputException('Enter author surname')

            author = Author(name=name, surname=surname)
            book_session.add(author)
            book_session.commit()

            self.clearAll()
            openDialog(QMessageBox.Information, 'Author inserted', 'Success')

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
コード例 #9
0
    def addFilmDirector(self):
        try:
            name = self.ui.filmDirectorName_lineEdit.text()
            surname = self.ui.filmDirectorSurname_lineEdit.text()

            if len(name) == 0:
                raise NoInputException('Enter film director name')
            if len(surname) == 0:
                raise NoInputException('Enter film director surname')

            filmDirector = Film_director(name=name, surname=surname)
            movie_session.add(filmDirector)
            movie_session.commit()

            self.clearAll()
            openDialog(QMessageBox.Information, 'Film director inserted',
                       'Success')

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
コード例 #10
0
    def editFilmDirector(self):
        try:
            name = self.ui.filmDirectorName_lineEdit.text()
            surname = self.ui.filmDirectorSurname_lineEdit.text()

            if len(name) == 0: raise NoInputException('Enter name of the author')
            elif len(surname) == 0: raise NoInputException('Enter surname of the author')

            if self.filmDirector.name != name or self.filmDirector.surname != surname:
                updates = {
                    'name': name,
                    'surname': surname
                }

                for key, value in updates.items():
                    setattr(self.filmDirector, key, value)

                movie_session.commit()
                openDialog(QMessageBox.Information, 'Film director edited', 'Success')
            else:
                openDialog(QMessageBox.Information, 'Nothing changed', 'Success')

            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
コード例 #11
0
    def addGenre(self):
        try:
            name = self.ui.genreName_lineEdit.text()
            if len(name) == 0: raise NoInputException('Enter genre name')

            genre = Genre(name=name)
            movie_session.add(genre)
            movie_session.commit()

            self.clearField()
            openDialog(QMessageBox.Information, 'Genre inserted', 'Success')

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
        except IntegrityError:
            openDialog(QMessageBox.Critical, 'Genre already inserted', 'Error')
            movie_session.rollback()
コード例 #12
0
    def editGenre(self):
        try:
            genre_name = self.ui.genreName_lineEdit.text()

            if len(genre_name) == 0:
                raise NoInputException('Enter the name of the genre')

            setattr(self.genre, 'name', genre_name)

            book_session.commit()

            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)

            openDialog(QMessageBox.Information, 'Genre edited', 'Success')

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
        except IntegrityError:
            openDialog(QMessageBox.Critical, 'Field already inserted', 'Error')
            book_session.rollback()
コード例 #13
0
    def editBook(self):
        try:
            book_title = self.ui.bookTitle_lineEdit.text()
            isbn = self.ui.bookIsbn_lineEdit.text()
            pages = self.ui.bookPages_lineEdit.text()
            year = str(self.ui.bookYear_comboBox.currentText())
            author = book_session.query(Author).filter_by(
                id=self.ui.bookAuthor_comboBox.currentIndex() + 1).first()
            genre = book_session.query(Genre).filter_by(
                id=self.ui.bookGenre_comboBox.currentIndex() + 1).first()
            status = book_session.query(BookStatus).filter_by(
                id=self.ui.bookStatus_comboBox.currentIndex() + 1).first()

            if len(book_title) == 0:
                raise NoInputException('Enter the title of book')
            elif len(isbn) == 0:
                raise NoInputException('Enter the ISBN of book')
            elif len(pages) == 0:
                raise NoInputException('Enter book number pages')
            elif author == None:
                raise NoInputException('Enter the author of the book')
            elif genre == None:
                raise NoInputException('Enter the genre of the book')

            if not pages.isdigit():
                raise NoNumericInputException('Pages value not valid')

            cover_path = self.ui.bookCoverPath_label.text()
            book_cover_path = self.book.cover_path

            if cover_path != book_cover_path:
                file_name = QUrl.fromLocalFile(cover_path).fileName()
                print(file_name)
                new_cover_path = join(COVER_PATH, file_name)
                shutil.copy(cover_path, new_cover_path)
                if cover_path != NO_COVER_AVAILABLE_PATH:
                    os.remove(book_cover_path)
            else:
                new_cover_path = self.book.cover_path

            description = self.ui.bookDescription_plainTextEdit.toPlainText()

            updates = {
                'title': book_title,
                'isbn': isbn,
                'pages': pages,
                'year': year,
                'author_id': author.id,
                'genre_id': genre.id,
                'cover_path': new_cover_path,
                'status_id': status.id,
                'description': description
            }

            for key, value in updates.items():
                setattr(self.book, key, value)

            book_session.commit()

            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)

            openDialog(QMessageBox.Information, 'Book edited', 'Success')

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
        except IntegrityError:
            openDialog(QMessageBox.Critical, 'Field already inserted', 'Error')
            book_session.rollback()
コード例 #14
0
    def addBook(self):
        try:
            book_title = self.ui.bookTitle_lineEdit.text()
            isbn = self.ui.bookIsbn_lineEdit.text()
            pages = self.ui.bookPages_lineEdit.text()
            year = int(self.ui.bookYear_comboBox.currentText())
            author = book_session.query(Author).filter_by(id=self.ui.bookAuthor_comboBox.currentIndex() + 1).first()
            genre = book_session.query(Genre).filter_by(id=self.ui.bookGenre_comboBox.currentIndex() + 1).first()
            cover_path = self.ui.bookCoverPath_label.text()
            description = self.ui.bookDescription_plainTextEdit.toPlainText()
            status = book_session.query(BookStatus).filter_by(id=self.ui.bookStatus_comboBox.currentIndex() + 1).first()


            if len(book_title) == 0: raise NoInputException('Enter the title of book')
            elif len(isbn) == 0: raise NoInputException('Enter the ISBN of book')
            elif len(pages) == 0: raise NoInputException('Enter book number pages')
            elif author == None: raise NoInputException('Enter the author of the book')
            elif genre == None: raise NoInputException('Enter the genre of the book')

            if not pages.isdigit(): raise NoNumericInputException('Pages value not valid')
            
            if len(cover_path) == 0:
                new_cover_path = NO_COVER_AVAILABLE_PATH
            else:
                file_name = QUrl.fromLocalFile(cover_path).fileName()
                new_cover_path = join(COVER_PATH, file_name)
                shutil.copy(cover_path, new_cover_path)

            print(new_cover_path)

            book = Book(title=book_title,
                        isbn=isbn,
                        pages=pages,
                        year=year,
                        author_id=author.id,
                        genre_id=genre.id,
                        description=description,
                        status_id=status.id,
                        cover_path=new_cover_path)
            
            book_session.add(book)
            book_session.commit()

            #results = session.query(Book, Author, Category).select_from(Book).join(Author).join(Category).all()
            #print(session.query(Book).join(Book.category_id).join(Book.author_id)).all()
            #for book, author, category in results:
                #print(book.title, author.name, author.surname, category.name)

            self.clearAll()

            openDialog(QMessageBox.Information, 'Book added', 'Success')

        except NoInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
        except NoNumericInputException as e:
            message = e.error_message
            openDialog(QMessageBox.Critical, message, 'Error')
        except IntegrityError:
            openDialog(QMessageBox.Critical, 'Book already inserted', 'Error')
            book_session.rollback()