def getValues(self):
        movies = movie_session.query(Movie).count()
        filmDirectors = movie_session.query(Film_director).count()
        genres = movie_session.query(Genre).count()

        self.ui.moviesCounter_label.setText(str(movies))
        self.ui.filmDirectorsCounter_label.setText(str(filmDirectors))
        self.ui.genresCounter_label.setText(str(genres))
    def loadData(self):
        results = movie_session.query(Movie, Film_director, Genre, MovieStatus).select_from(Movie).join(Film_director).join(Genre).join(MovieStatus).all()
        self.model = QStandardItemModel(len(results), len(self.labels))
        self.model.setHorizontalHeaderLabels(self.labels)

        self.filter_proxy_model = QSortFilterProxyModel()
        self.filter_proxy_model.setFilterKeyColumn(-1)
        self.filter_proxy_model.setSourceModel(self.model)

        for row, (movie, film_director, genre, movie_status) in enumerate(results):
            movie_id = QStandardItem(str(movie.id))
            movie_id.setTextAlignment(Qt.AlignCenter)
            movie_title = QStandardItem(movie.title)
            movie_title.setTextAlignment(Qt.AlignCenter)
            filmDirector = QStandardItem(film_director.name + " " + film_director.surname)
            filmDirector.setTextAlignment(Qt.AlignCenter)
            genreI = QStandardItem(genre.name)
            genreI.setTextAlignment(Qt.AlignCenter)
            status = QStandardItem(movie_status.name)
            status.setTextAlignment(Qt.AlignCenter)
            status.setForeground(QBrush(getColorStatus(movie.status_id, movie)))

            self.model.setItem(row, 0, movie_id)
            self.model.setItem(row, 1, movie_title)
            self.model.setItem(row, 2, filmDirector)
            self.model.setItem(row, 3, genreI)
            self.model.setItem(row, 4, status)

        self.ui.allMovies_tableView.setModel(self.filter_proxy_model)
        self.ui.allMovies_tableView.setColumnHidden(0, True)

        self.ui.searchMovie_lineEdit.textChanged.connect(self.filter_proxy_model.setFilterRegExp)
Esempio n. 3
0
    def loadData(self):
        filmDirectors = movie_session.query(Film_director).all()
        self.model = QStandardItemModel(len(filmDirectors), len(self.labels))
        self.model.setHorizontalHeaderLabels(self.labels)

        self.filter_proxy_model = QSortFilterProxyModel()
        self.filter_proxy_model.setFilterKeyColumn(-1)
        self.filter_proxy_model.setSourceModel(self.model)

        for row, filmDirector in enumerate(filmDirectors):
            filmDirector_id = QStandardItem(str(filmDirector.id))
            filmDirector_id.setTextAlignment(Qt.AlignCenter)
            filmDirector_name = QStandardItem(filmDirector.name)
            filmDirector_name.setTextAlignment(Qt.AlignCenter)
            filmDirector_surname = QStandardItem(filmDirector.surname)
            filmDirector_surname.setTextAlignment(Qt.AlignCenter)

            self.model.setItem(row, 0, filmDirector_id)
            self.model.setItem(row, 1, filmDirector_name)
            self.model.setItem(row, 2, filmDirector_surname)

        self.ui.allFilmDirectors_tableView.setModel(self.filter_proxy_model)
        self.ui.allFilmDirectors_tableView.setColumnHidden(0, True)

        self.ui.searchFilmDirector_lineEdit.textChanged.connect(
            self.filter_proxy_model.setFilterRegExp)
Esempio n. 4
0
 def editGenre(self):
     row = self.ui.allGenres_tableView.selectionModel().selectedRows(
     )[0].row()
     id = self.filter_proxy_model.index(row, 0).data()
     genre = movie_session.query(Genre).filter_by(id=id).first()
     genre_view = self.parent().findChild(QWidget, 'genre_window')
     genre_view.updateValues(genre)
     self.parent().setCurrentWidget(genre_view)
    def movie_details(self):
        row = self.ui.allMovies_tableView.selectionModel().selectedRows()[0].row()
        id = self.filter_proxy_model.index(row, 0).data()
        result = movie_session.query(Movie, Film_director, Genre, MovieStatus).select_from(Movie).filter_by(id=id).join(Film_director).join(Genre).join(MovieStatus).first()

        movie, film_director, genre, status = result
        movie_view = self.parent().findChild(QWidget, 'movie_window')
        movie_view.updateValues(movie, film_director, genre, status)
        self.parent().setCurrentWidget(movie_view)
Esempio n. 6
0
 def filmDirector_details(self):
     row = self.ui.allFilmDirectors_tableView.selectionModel().selectedRows(
     )[0].row()
     id = self.filter_proxy_model.index(row, 0).data()
     filmDirector = movie_session.query(Film_director).filter_by(
         id=id).first()
     filmDirector_view = self.parent().findChild(QWidget,
                                                 'filmDirector_window')
     filmDirector_view.updateValues(filmDirector)
     self.parent().setCurrentWidget(filmDirector_view)
Esempio n. 7
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')
Esempio n. 8
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')
    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')

            
Esempio n. 10
0
def getColorStatus(status_id, model):

    #MOLTO PIÙ STRUTTURATO RISPETTO A DEI SEMPLICI CONTROLLI CON I NUMERI

    status_dict = {
        'Not readed': QColor(255, 0, 0),
        'In progress': QColor(0, 0, 255),
        'Readed': QColor(0, 100, 0),
        'Not watched': QColor(255, 0, 0),
        'Watched': QColor(0, 100, 0)
    }
    if isinstance(model, Book):
        all_status = book_session.query(BookStatus).all()
    else:
        all_status = movie_session.query(MovieStatus).all()

    for status in all_status:
        if status.id == status_id:
            return status_dict[status.name]
Esempio n. 11
0
    def loadData(self):
        genres = movie_session.query(Genre).all()
        self.model = QStandardItemModel(len(genres), len(self.labels))
        self.model.setHorizontalHeaderLabels(self.labels)

        self.filter_proxy_model = QSortFilterProxyModel()
        self.filter_proxy_model.setFilterKeyColumn(-1)
        self.filter_proxy_model.setSourceModel(self.model)

        for row, genre in enumerate(genres):
            genre_id = QStandardItem(str(genre.id))
            genre_id.setTextAlignment(Qt.AlignCenter)
            genre_name = QStandardItem(genre.name)
            genre_name.setTextAlignment(Qt.AlignCenter)
            self.model.setItem(row, 0, genre_id)
            self.model.setItem(row, 1, genre_name)

        self.ui.allGenres_tableView.setModel(self.filter_proxy_model)
        self.ui.allGenres_tableView.setColumnHidden(0, True)

        self.ui.searchGenre_lineEdit.textChanged.connect(
            self.filter_proxy_model.setFilterRegExp)
Esempio n. 12
0
    def updateValues(self, movie, film_director, genre, status):
        self.movie = movie
        self.film_director = film_director
        self.genre = genre
        self.status = status

        self.ui.movieYear_comboBox.clear()
        self.ui.filmDirector_comboBox.clear()
        self.ui.movieGenre_comboBox.clear()
        self.ui.movieStatus_comboBox.clear()

        for year in range(FIRST_YEAR_MOVIE, ACTUAL_YEAR):
            self.ui.movieYear_comboBox.addItem(str(year))

        film_directors = movie_session.query(Film_director).all()
        if len(film_directors) == 0:
            self.ui.filmDirector_comboBox.addItem('No authors founded')
            self.ui.filmDirector_comboBox.setDisabled(True)
        else:
            for film_director in film_directors:
                self.ui.filmDirector_comboBox.addItem(
                    str(film_director.name + ' ' + film_director.surname))
            self.ui.filmDirector_comboBox.setDisabled(False)

        genres = movie_session.query(Genre).all()
        if len(genres) == 0:
            self.ui.movieGenre_comboBox.addItem('No genres founded')
            self.ui.movieGenre_comboBox.setDisabled(True)
        else:
            for genre in genres:
                self.ui.movieGenre_comboBox.addItem(genre.name)
            self.ui.movieGenre_comboBox.setDisabled(False)

        all_status = movie_session.query(MovieStatus).all()
        for status in all_status:
            self.ui.movieStatus_comboBox.addItem(status.name)

        hour = self.movie.film_length // 60
        minutes = self.movie.film_length % 60

        # FIRST TAB
        self.ui.movieTitle_label.setText(self.movie.title + ', ' +
                                         self.film_director.name + ' ' +
                                         self.film_director.surname)
        self.ui.movieLength_label.setText(
            str(hour) + ' hour, ' + str(minutes) + ' minutes')
        self.ui.movieYear_label.setText(str(self.movie.year))
        image = QPixmap(self.movie.cover_path)
        image = image.scaled(self.ui.movieCover_label.width(),
                             self.ui.movieCover_label.height(),
                             QtCore.Qt.KeepAspectRatio)
        self.ui.movieCover_label.setPixmap(image)
        self.ui.movieCover_label.setScaledContents(True)
        self.ui.movieGenre_label.setText(self.genre.name)
        self.ui.movieDescription_label.setText(self.movie.description)

        # SECOND TAB
        self.ui.movieTitle_lineEdit.setText(self.movie.title)
        self.ui.movieCoverPath_label.setText(self.movie.cover_path)

        self.ui.hour_spinBox.setValue(self.movie.film_length // 60)
        self.ui.minutes_spinBox.setValue(self.movie.film_length % 60)

        self.ui.movieYear_comboBox.setCurrentText(str(self.movie.year))
        self.ui.filmDirector_comboBox.setCurrentIndex(self.film_director.id -
                                                      1)
        self.ui.movieGenre_comboBox.setCurrentIndex(self.genre.id - 1)
        self.ui.movieStatus_comboBox.setCurrentIndex(self.status.id - 1)

        self.ui.movieDescription_plainTextEdit.setPlainText(
            self.movie.description)
Esempio n. 13
0
                                    genre_id=genre.id,
                                    status_id=status.id)
        book_session.add(new_book)
    book_session.commit()

    movies = data['movies']
    for movie in movies:
        title = movie['title']
        film_length = movie['film_length']
        year = movie['year']
        description = movie['description']

        film_director_name = movie['film_director']['name']
        film_director_surname = movie['film_director']['surname']
        film_director = movie_session.query(
            movie_models.Film_director).filter_by(
                name=film_director_name,
                surname=film_director_surname).first()
        if not film_director:
            film_director = movie_models.Film_director(
                name=film_director_name, surname=film_director_surname)
            movie_session.add(film_director)
            movie_session.commit()

        genre_name = movie['genre']
        genre = movie_session.query(
            movie_models.Genre).filter_by(name=genre_name).first()
        if not genre:
            genre = movie_models.Genre(name=genre_name)
            movie_session.add(genre)
            movie_session.commit()